PKI.js is a pure JavaScript library implementing the formats that are used in PKI applications (signing, encryption, certificate requests, OCSP and TSP requests/responses). It is built on WebCrypto (Web Cryptography API) and requires no plug-ins.
Hi, I'm trying to load an encrypted PKCS#8 private key without success.
Here is my code. In the first part i load an unecrypted PKCS#8 key with success, in hte second part I try loading the encrypted key with error:
// Load Private Key PKCS#8
let buffer1 = pvtsutils.BufferSourceConverter.toArrayBuffer(await Deno.readFile("./domain-pkcs8-nocrypt.key"));
let bynary1 = pvtsutils.Convert.ToBinary(buffer1);
let ber = decodePEM(bynary1, "PRIVATE KEY")[0];
let key = pkijs.PrivateKeyInfo.fromBER(ber);
console.log(key); // --->>> OK
// This fails
buffer1 = pvtsutils.BufferSourceConverter.toArrayBuffer(await Deno.readFile("./domain-pkcs8.key"));
bynary1 = pvtsutils.Convert.ToBinary(buffer1);
ber = decodePEM(bynary1, "ENCRYPTED PRIVATE KEY")[0];
key = pkijs.PrivateKeyInfo.fromBER(ber);
console.log(key);
error: Uncaught (in promise) AsnError: Cannot create 'PrivateKeyInfo' from ASN.1 object
throw new AsnError(`Cannot create '${this.CLASS_NAME}' from ASN.1 object`);
Hi, I'm trying to load an encrypted PKCS#8 private key without success. Here is my code. In the first part i load an unecrypted PKCS#8 key with success, in hte second part I try loading the encrypted key with error:
Keys are generated and converted like this: