【发布时间】:2021-03-24 12:46:51
【问题描述】:
我有一个证书,上面写着 Signature Algorithm 是 sha256WithRSAEncryption 而 Key Size 是 1024。
我正在尝试使用Web Crypto API 加密一些任意数据,并且只能通过使用以下参数导入证书密钥来成功加密它
return await window.crypto.subtle.importKey(
'spki',
buffer, // binary format of the key
{
name: 'RSA-OAEP',
hash: 'SHA-256',
},
true,
['encrypt'],
);
然后使用以下参数加密数据
await crypto.encrypt({ name: 'RSA-OAEP' }, cryptoKey, chunk); // max of 62 bytes of data given the key size and algorithm
我的问题是,这是与此特定键一起使用的唯一可能组合吗?
向我颁发公钥的人说,他们希望使用 RSA-PKCS1-KeyEx 的算法和 rsa-sha1 的哈希值和 117 字节大小的数据块来加密数据。
鉴于我对密码学的理解非常有限,我相信RSA-PKCS1-KeyEx 只能用于signing 而不能加密,并且您通常使用私钥而不是公开密钥进行签名。
即使将importKey 的参数更改为使用RSASSA-PKCS1-v1_5 和sha-1 也会引发错误,显示Cannot create a key using the specified key usages.
是否甚至可以使用证书/密钥为 sha256WithRSAEncryption 和密钥大小为 1024 的这些参数,或者我目前的方式是使用密钥和加密数据的唯一可能方式?
【问题讨论】:
标签: javascript encryption rsa webcrypto-api