# pki-lib

> The PKI Library

Latest version **0.2.0** (published 2017-12-20) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install pki-lib
pnpm add pki-lib
yarn add pki-lib
bun add pki-lib
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2017-12-20 |
| First published | 2017-11-17 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kapil Sachdeva |
| Maintainers | ksachdeva |

## Links

- npm: https://www.npmjs.com/package/pki-lib
- Repository: https://github.com/ksachdeva/pki
- Homepage: https://github.com/ksachdeva/pki#readme
- Issues: https://github.com/ksachdeva/pki/issues
- npm.io page: https://npm.io/package/pki-lib

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.8.0

## Recent versions

- 0.2.0 (latest) — 2017-12-20
- 0.1.2 — 2017-12-20
- 0.1.1 — 2017-11-17
- 0.1.0 — 2017-11-17

## README

# pki-lib

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

[![npm version](https://badge.fury.io/js/pki-lib.svg)](https://badge.fury.io/js/pki-lib) 

The library requires you to pass an implementation of ICryptoEngine. Look at
* [test-crytpo-engine.ts](./src/tests/test-crypto-engine.ts) test script to see an implementation of a crypto engine.
* [basic-pki.ts](./src/examples/basic-pki.ts) script for a full example

## Generating a root CA certificate

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

---
_Source: https://npm.io/package/pki-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
