pki-lib
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

pki-lib

The core library that provides support for generating X509Certificate and Certificate Signing Request.

npm version

The library requires you to pass an implementation of ICryptoEngine. Look at

Generating a root CA certificate

const cryptoEngine = new TestCryptoEngine();
 
const notBefore = new Date();
const notAfter = new Date();
notAfter.setFullYear(notBefore.getFullYear() + 1);
 
const hashAlg = 'SHA1withRSA';
const signAlg = 'RSASSA-PKCS1-v1_5';
 
// generate the key pair
const keyPair: CryptoKeyPair =
    await cryptoEngine.generateKey({
        name: signAlg,
        modulusLength: 1024,
        publicExponent: new Uint8Array([1, 0, 1]),
        hash: {
            name: 'SHA-1'
        }
    }, true, ['sign', 'verify']) as CryptoKeyPair;
 
const x509CertInfo: X509CertificateInfo = {
    isCA: true,
    signAlg,
    hashAlg,
    serialNumber: '01',
    subjectInfo: {
        commonName: 'example.org',
        country: 'US',
        state: 'TX',
        orgName: 'Test',
        orgUnit: 'Test'
    },
    issuerInfo: {
        commonName: 'example.org',
        country: 'US',
        state: 'TX',
        orgName: 'Test',
        orgUnit: 'Test'
    },
    validity: {
        notBefore,
        notAfter 
    },
    publicKey: keyPair.publicKey,
    issuerPrivateKey: keyPair.privateKey
};
 
const jsX509 =
    await X509Util.buildCertificate(new TestCryptoEngine(), x509CertInfo);

Readme

Keywords

none

Package Sidebar

Install

npm i pki-lib

Weekly Downloads

0

Version

0.2.0

License

Apache-2.0

Last publish

Collaborators

  • ksachdeva