我尝试将ASN.1序列"AgER“转换为CryptoPP::Integer。
#include <crypto++/asn.h>
#include <iostream>
int main(int, char*[])
{
std::string base64{"AgER"};
CryptoPP::StringSource s{base64, true};
CryptoPP::BERSequenceDecoder d{s};
CryptoPP::Integer i;
i.BERDecode(d);
std::cout << i.ConvertToLong() << std::endl;
}这抛出了一个带有消息"BER decode error“的CryptoPP::BERDecodeErr类型的异常。
不同的ASN.1工具可以毫无问题地解析字符串:https://lapo.it/asn1js/#AgER
发布于 2020-06-17 17:22:58
我发现Crypto++需要二进制数据,而不是Base64编码的数据。所以我之前必须破解这个。
这里是工作解决方案;
#include <crypto++/asn.h>
#include <crypto++/base64.h>
#include <iostream>
int main(int, char*[])
{
std::string base64{"AgER"};
std::string decoded;
CryptoPP::StringSource{base64, true, new CryptoPP::Base64Decoder{new CryptoPP::StringSink{decoded}}};
CryptoPP::StringSource s{decoded, true};
CryptoPP::Integer i;
i.BERDecode(s);
std::cout << i.ConvertToLong() << std::endl;
}https://stackoverflow.com/questions/62412128
复制相似问题