Jsrasign,将公钥加载到RSAKey()?

时间:2017-05-09 11:32:45

标签: javascript cryptography public-key

我有pem格式的公钥,我无法弄清楚如何对其进行编码以将其加载到RSAKey()对象中。该库提供了3种公钥读取方法:readCertPubKeyHex, readPKCS5PubKeyHex, readPKCS8PubKeyHex但我无法弄清楚如何为这些方法编码pem文件,我已经尝试了pem文件的base64编码体并转换为十六进制但是最终导致以下错误之一:not ASN.1 hex stringnot PKCS8 RSA public keywrong hex for PKCS#5 public key

let rsa = new RSAKey();
rsa.readCertPubKeyHex("?? Ansi Hex ??");
let verified_config = rsa.verifyStringPSS(message, signature, "SHA512", 2);

如果需要,我愿意重新生成公钥/私钥对。

1 个答案:

答案 0 :(得分:1)

我忽略了一些非常有用的工具来为你做这个,代码应该看起来像:

let rsa = KEYUTIL.getKey("-----BEGIN PUBLIC KEY-----***yourPublicKeyHere-----END PUBLIC KEY-----");

let verified_config = rsa.verifyStringPSS(message, signature, "SHA512", 2);