I am using the following code to generate a pair key:
var fs = require('fs');
var SubtleCrypto = require('subtle');
SubtleCrypto.generateKey({
name: 'RSASSA-PKCS1-v1_5',
modulusLength: 4096,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: {name: 'SHA-256'}
}, true, ['sign', 'verify'])
.then(function (keyPair) {
SubtleCrypto.exportKey('spki', keyPair.publicKey)
.then(function (publicKey) {
fs.writeFileSync('public.der', new Buffer(publicKey));
});
SubtleCrypto.exportKey('pkcs8', keyPair.privateKey)
.then(function (privateKey) {
fs.writeFileSync('private.der', new Buffer(privateKey));
});
});
But I am unable to open them and display them with OpenSSL:
openssl x509 -inform der -in public.der -noout -text
unable to load certificate
43845:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/asn1/tasn_dec.c:1341:
43845:error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/asn1/tasn_dec.c:845:
43845:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/asn1/tasn_dec.c:765:Field=serialNumber, Type=X509_CINF
43845:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/asn1/tasn_dec.c:765:Field=cert_info, Type=X509
openssl x509 -inform der -in private.der -noout -text
unable to load certificate
43936:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/asn1/tasn_dec.c:1341:
43936:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/asn1/tasn_dec.c:385:Type=X509_CINF
43936:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/asn1/tasn_dec.c:765:Field=cert_info, Type=X509
Am I doing something wrong or does Subtle crypto not use standard formats?
I am using the following code to generate a pair key:
But I am unable to open them and display them with OpenSSL:
Am I doing something wrong or does Subtle crypto not use standard formats?