我在下面https://github.com/digitalbazaar/forge#pkcs12这些步骤将pem-cert转换为p12。我想要二进制格式的.p12证书,不想像上面链接中提到的那样使用base64对其进行进一步编码。如果我跳过最后一步
var p12b64 = forge.util.encode64(p12Der);
然后从输出文件(其中包含字节,即p12Der(中,我无法使用openSSL提取证书和密钥。提取证书所遵循的步骤:
openssl pkcs12 -in enc.p12 -out cert.crt -nokeys -clcerts
Which throws following error
4145202984:error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long:asn1_lib.c:157:
如何使用生成二进制格式的p12文件https://github.com/digitalbazaar/forge#pkcs12这些步骤而不进行编码(即跳过创建p12b64的最后一步(?
另外,如何使用纯JS(无节点(下载此文件?
适合我。
$ cat 71308138.js
const fs = require('fs'), forge = require('node-forge');
var key = forge.pki.privateKeyFromPem(fs.readFileSync("71308138.key",'ascii'));
var crt = forge.pki.certificateFromPem(fs.readFileSync("71308138.crt",'ascii'));
var asn1 = forge.pkcs12.toPkcs12Asn1(key,crt,'password',{algorithm:'3des'});
var der = forge.asn1.toDer(asn1).getBytes();
fs.writeFileSync("71308138.p12",der,'binary');
$ nodejs 71308138.js
$ openssl pkcs12 -in 71308138.p12 -password pass:password -info -nodes
MAC: sha1, Iteration 2048
MAC length: 20, salt length: 8
PKCS7 Data
Certificate bag
Bag Attributes
localKeyID: CB 1E 24 AF CF 80 D2 60 D0 1E A5 E1 3C 7F CB 35 CF F7 A2 D5
subject=CN = 71308138
issuer=CN = 71308138
-----BEGIN CERTIFICATE-----
MIICAjCCAWugAwIBAgIUSMMnVr3zmLgs0o2CL9jCDvS2mRAwDQYJKoZIhvcNAQEL
BQAwEzERMA8GA1UEAwwINzEzMDgxMzgwHhcNMjIwMzAzMDYwNTMxWhcNMjIwNDAy
MDYwNTMxWjATMREwDwYDVQQDDAg3MTMwODEzODCBnzANBgkqhkiG9w0BAQEFAAOB
jQAwgYkCgYEAwnMSHu6OBCdp5Zy3lRY9QieDc8Uyb62KRZeoHmnp9E5jDb8Tdxpb
tkg8ewr2SUKj7HBjiRZWDDclhSskqND5isqxgIpFbKOiiDyP7DtgqqaUqg5N6Hn7
5ZhajK//x+Xadjo8PKcKyisUOoAkOBy9ztcWPJ0pFZG8MVlkwykg61cCAwEAAaNT
MFEwHQYDVR0OBBYEFO1A7mfsya5J2fv7x9p480LjXj3yMB8GA1UdIwQYMBaAFO1A
7mfsya5J2fv7x9p480LjXj3yMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL
BQADgYEAuqCOu2pbN9nVcPB57/c1Ja3HKLHZx6tjif/4gy3c6OALT8h9LfU0Xl++
kJlNXdaCSTDEDCQsRPUGwzTbALBlzHMc905WsbSqywUe3pgNjPw/+dBz42v9hD0p
ztiZr+2g8iQZpib1vc+xlBTPJ7b/av0EaYkh4hCGRq5cYnjL+Tk=
-----END CERTIFICATE-----
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048
Bag Attributes
localKeyID: CB 1E 24 AF CF 80 D2 60 D0 1E A5 E1 3C 7F CB 35 CF F7 A2 D5
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMJzEh7ujgQnaeWc
t5UWPUIng3PFMm+tikWXqB5p6fROYw2/E3caW7ZIPHsK9klCo+xwY4kWVgw3JYUr
JKjQ+YrKsYCKRWyjoog8j+w7YKqmlKoOTeh5++WYWoyv/8fl2nY6PDynCsorFDqA
JDgcvc7XFjydKRWRvDFZZMMpIOtXAgMBAAECgYA8Q1tvWLGM2gY40iwXOXA8y3Ay
9f+emuMKlGjXHC4UuCJ8xSYsOHAJ+zM7UvdnVw7knSRL/S8n1AN91RQkebeMYGSJ
RtsVip4Plfh1DQVA+8QYDhqibIa3hhYkBE8TBmfHNcpLkVooskU7ZPiJ8DRBdi43
yI5hRPP3O3PvtbzbGQJBAPKIIOgYKTc5rMbjBMryAFonRuSXO2vXc2pQhoYa7ggr
oVgDWsi1W33Io4u4/bI4K2iyzqTuyx8lXkyCp7ZEJqsCQQDNP2WdjydYcyovFG7g
NqC05qPhzIzGPBcrNR2qGcvYIIZKYBa/Kt40UqosXm+vEqGMNqkcSSP52jc4wXK8
TH4FAkAEe0V4ZHHmhldN+YXuJhihkdY6hRzg+kM0tLY3pim91uiNUsqLqOY+5cU3
4Lw3XdhXf+5Xl94C/lLGwSdOM+YvAkAwa6VoX05T8o9gHfzuTlTpeIPvEBeh6Kk6
m0RNTdqmOT4VK8gR/2X+iAX3g6vrbITKFFcfAi5HknB2pkSQIaeVAkAil33xA/wg
SjTvcO33u4vkViLCioo/MZWr+V8FAw94yLvAmp2AD+vCA2Tx7Wk0Reh+PoR1YP2R
O9Gkz+6UdiwA
-----END PRIVATE KEY-----
$