HTML5 的加密模块到 RSA public 加密
Crypto module of HTML5 to RSA public encrypt
如何使用 public 密钥和 PKCS 填充通过 RSA 进行加密,我一直在尝试这样做,但一直坚持导入密钥,到目前为止我有这个:
crypto.subtle.importKey('spki', key, {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'SHA-256'}}, false, ['encrypt']).then(i => console.log(i)).catch(err => console.warn(err.message))
key
是一个key,当然是用TextEncoder
编码的。这给了我一个错误 Cannot create a key using the specified key usages
.
我为 AES-CBC 做了导入并成功 encryption/decryption 并且想为 RSA 做同样的事情,任何帮助将不胜感激。
P.S. 我尽量不为此使用库,所以这应该是最后的选择。
“RSASSA-PKCS1-v1_5”中的“SSA”代表“Signature Scheme with Appendix”,所以它是一种签名算法,不能与“encrypt”密钥用法一起使用。
使用 PKCS#1 填充的 RSA 加密算法为“RSAES-PKCS1-v1_5”,但根据 https://www.chromium.org/blink/webcrypto it's not supported ("Chrome supported this in early days before Web Crypto was enabled by default, but has since dropped support."). Here's more information about why it's not supported: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-webcrypto-algorithms-00#section-5 .
对于 WebCrypto 中的 RSA 加密,似乎唯一支持的填充是 RSA-OAEP。
如何使用 public 密钥和 PKCS 填充通过 RSA 进行加密,我一直在尝试这样做,但一直坚持导入密钥,到目前为止我有这个:
crypto.subtle.importKey('spki', key, {name: 'RSASSA-PKCS1-v1_5', hash: {name: 'SHA-256'}}, false, ['encrypt']).then(i => console.log(i)).catch(err => console.warn(err.message))
key
是一个key,当然是用TextEncoder
编码的。这给了我一个错误 Cannot create a key using the specified key usages
.
我为 AES-CBC 做了导入并成功 encryption/decryption 并且想为 RSA 做同样的事情,任何帮助将不胜感激。
P.S. 我尽量不为此使用库,所以这应该是最后的选择。
“RSASSA-PKCS1-v1_5”中的“SSA”代表“Signature Scheme with Appendix”,所以它是一种签名算法,不能与“encrypt”密钥用法一起使用。
使用 PKCS#1 填充的 RSA 加密算法为“RSAES-PKCS1-v1_5”,但根据 https://www.chromium.org/blink/webcrypto it's not supported ("Chrome supported this in early days before Web Crypto was enabled by default, but has since dropped support."). Here's more information about why it's not supported: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-webcrypto-algorithms-00#section-5 .
对于 WebCrypto 中的 RSA 加密,似乎唯一支持的填充是 RSA-OAEP。