我正在使用forge库创建一个 .p12 格式的自签名证书,该证书使用WebCryptoAPI生成私钥-公钥对。但是,当我尝试在 Windows 证书存储中导入 .p12 文件时,出现以下错误:
这个链接说私钥可能有问题。
以下是我通过 webcryptoApi 生成的密钥片段
window.crypto.subtle.generateKey({
name: 'RSA-PSS',
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: {name: 'SHA-1'}
}
我生成 p12 的伪造代码片段如下:
var newPkcs12Asn1 = forge.pkcs12.toPkcs12Asn1(
keys.privateKey, [cert], password,
{generateLocalKeyId: true, friendlyName: 'test'},
{algorithm: '3des'});
var newPkcs12Der = forge.asn1.toDer(newPkcs12Asn1).getBytes();
var p12b64 = forge.util.encode64(newPkcs12Der);
var downloadLink = document.createElement("a");
downloadLink.download = "example.p12";
downloadLink.innerHTML = "Download File";
downloadLink.setAttribute('href', 'data:application/x-pkcs12;base64,' + p12b64);
downloadLink.style.display = "none";
downloadLink.click();
笔记 :
- 我也无法在 Mozilla 证书存储中导入文件。那么p12文件可能有问题吗?
- Windows 证书存储在导入时正确验证我的私钥密码,仅完成阶段失败。