🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

pki-lib

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pki-lib

The PKI Library

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
10
Maintainers
1
Weekly downloads
 
Created
Source

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

  • test-crytpo-engine.ts test script to see an implementation of a crypto engine.
  • basic-pki.ts script for a full example

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);

FAQs

Package last updated on 20 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts