我有pem格式的公钥,我无法弄清楚如何对其进行编码以将其加载到RSAKey()
对象中。该库提供了3种公钥读取方法:readCertPubKeyHex, readPKCS5PubKeyHex, readPKCS8PubKeyHex
但我无法弄清楚如何为这些方法编码pem文件,我已经尝试了pem文件的base64编码体并转换为十六进制但是最终导致以下错误之一:not ASN.1 hex string
,not PKCS8 RSA public key
或wrong hex for PKCS#5 public key
。
let rsa = new RSAKey();
rsa.readCertPubKeyHex("?? Ansi Hex ??");
let verified_config = rsa.verifyStringPSS(message, signature, "SHA512", 2);
如果需要,我愿意重新生成公钥/私钥对。
答案 0 :(得分:1)
我忽略了一些非常有用的工具来为你做这个,代码应该看起来像:
let rsa = KEYUTIL.getKey("-----BEGIN PUBLIC KEY-----***yourPublicKeyHere-----END PUBLIC KEY-----");
let verified_config = rsa.verifyStringPSS(message, signature, "SHA512", 2);