从 unsigned char 数组加载 public 键

Load public key from unsigned char array

我有一个 public 键作为来自 xxd:

的字节数组
unsigned char publicKey_txt[] = {
 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, .. }; 

根据之前的 Stack Overflow 问题,我有一个大致的理解,在我的情况下,StringSink 后跟加载应该有效

StringSource publicstring(publicKey_txt, true, NULL);
publicKey.Load(publicstring);

只需从文本文件加载即可,但当我从 StringSink 加载时出现错误:

Error: BER decode error

如何从无符号字符数组加载 public 密钥?

找到我的答案from @jww - Load RSA PKCS#1 private key from memory?

在我的例子中,我使用 ArraySource 而不是 SinkSource 稍作修改,publicKey_txt_len 是 char 数组的大小 publicKey_txt。

CryptoPP::ArraySource as( publicKey_txt, publicKey_txt_len, true);
publicKey.Load(as);