# pem2jwk-parser

> A tool to convert a PEM file to a JSON Web Key (JWK). AThe package provides methods to convert both public and private PEM files, as well as a method to convert a private PEM to a public JWK.

Latest version **2.2.2** (published 2023-02-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install pem2jwk-parser
pnpm add pem2jwk-parser
yarn add pem2jwk-parser
bun add pem2jwk-parser
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.2 |
| Published | 2023-02-09 |
| First published | 2023-02-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | pmartinsdev |
| Maintainers | pmartinsdev |
| Keywords | pem2jwk, converter, jwk, PEM, pemtojwk, pem-jwk |

## Links

- npm: https://www.npmjs.com/package/pem2jwk-parser
- Repository: https://github.com/pmartinsdev/pem2jwk-parser
- Homepage: https://github.com/pmartinsdev/pem2jwk-parser#readme
- Issues: https://github.com/pmartinsdev/pem2jwk-parser/issues
- npm.io page: https://npm.io/package/pem2jwk-parser

## Dependencies (1)

- [pem-jwk](https://npm.io/package/pem-jwk.md) ^2.0.0

## Recent versions

- 2.2.2 (latest) — 2023-02-09
- 2.2.1 — 2023-02-09
- 2.2.0 — 2023-02-09
- 2.1.0 — 2023-02-02
- 2.0.0 — 2023-02-02
- 1.0.1 — 2023-02-02
- 1.0.0 — 2023-02-02

## README

# Pem2Jwk

A tool to convert a PEM file to a JSON Web Key (JWK). AThe package provides methods to convert both public and private PEM files, as well as a method to convert a private PEM to a public JWK.

## Requirements

- [OpenSSL](https://www.openssl.org/docs/man1.1.0/man3/RSA_generate_key.html) 1.1.0 or later

## Table of Contents

- [fromPublic](#frompublic)
- [fromPrivate](#fromprivate)
- [fromPrivateToPublic](#fromprivatetopublic)

---

## fromPublic

This method takes a public PEM file and converts it to a JSON Web Key (JWK).

#### Syntax

```typescript
Pem2Jwk.fromPublic<T>(publicPem: PEM, extraKeys?: T): PublicJWK<T>
```

#### Parameters

- `publicPem`: The public PEM file. Can be a string or a Buffer.
- `extraKeys` (optional): An object that provides additional information to be included in the JWK.

#### Return Value

The public JWK.

#### Example

```typescript
const publicPem = `-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----`;
const publicJwk = Pem2Jwk.fromPublic(publicPem);
console.log(publicJwk);
```

---

## fromPrivate

This method takes a private PEM file and converts it to a JSON Web Key (JWK).

#### Syntax

```typescript
Pem2Jwk.fromPrivate<T>(privatePem: PEM, extraKeys?: T): PrivateJWK<T>
```

#### Parameters

- `privatePem`: The private PEM file. Can be a string or a Buffer.
- `extraKeys` (optional): An object that provides additional information to be included in the JWK.

#### Return Value

The private JWK.

#### Example

```typescript
const privatePem = `-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----`;

const privateJwk = Pem2Jwk.fromPrivate(privatePem);
console.log(privateJwk);
```

---

## fromPrivateToPublic

This method converts a private PEM key to a public JWK. The private PEM key is passed as a parameter to the method, and the public JWK is returned.

The method works by first creating a temporary PEM file from the private PEM key and then using `openssl` to generate a public key from that file. The public key is then converted to a JWK using the `fromPublic` method.

#### Syntax

```typescript
Pem2Jwk.fromPrivateToPublic<T>(privatePem: PEM, extraKeys?: T): Promise<PublicJWK<T>>
```

#### Parameters

- `privatePem`: The private PEM file. Can be a string or a Buffer.
- `extraKeys` (optional): An object that provides additional information to be included in the JWK.

#### Return Value

A Promise that resolves to the public JWK.

#### Example

```typescript
const privatePem = `-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----`;

Pem2Jwk.fromPrivateToPublic(privatePem).then(publicJwk => {
  console.log(publicJwk);
});
```

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