如何查看WebCryptoAPI中实际生成的密钥对
我已经使用如何查看WebCryptoAPI中实际生成的密钥对,web,Web,我已经使用 window.crypto.subtle.generateKey({ name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, //can be 1024, 2048, or 4096 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), hash: { name: "SHA-256" } //can be "SHA-1", "SHA-256", "SHA-384"
window.crypto.subtle.generateKey({
name: "RSASSA-PKCS1-v1_5",
modulusLength: 2048, //can be 1024, 2048, or 4096
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: { name: "SHA-256" } //can be "SHA-1", "SHA-256", "SHA-384", or "SHA-512"
},
true,
["sign", "verify"]
).then(function(keyPair) {
console.log("Exporting from keyPair", keyPair);
console.log("type pf key",typeof(keyPair.publicKey))
})
.catch(function(err) {
console.error(err);
});
但是日志会将公钥和私钥显示为对象,而不会在字符串中实际表示生成的密钥。有没有办法找出键的实际生成字符串值 如果需要清除密钥,则需要导出密钥:
window.crypto.subtle.exportKey(
"jwk", //can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only)
publicKey //can be a publicKey or privateKey, as long as extractable was true
)
.then(function(keydata){
//returns the exported key data
console.log(keydata);
})
.catch(function(err){
console.error(err);
});
也就是说,出于安全原因,您只想使用不可导出的密钥,而不想自己处理密钥。您好,欢迎来到Stack Overflow,请花点时间浏览一下,了解一下您在这里的做法,并获得您的第一个徽章,阅读如何创建一个和检查,以增加获得反馈和有用答案的机会。