0.0.5 • Published 3 years ago

@postnord/pretty-crypto v0.0.5

Weekly downloads
-
License
Proprietary
Repository
-
Last release
3 years ago

A library that handles the hustle of implementing a safe, efficient and asynchronous set of methods to handle encryption and decryption. It also exposes the interfaces necessary to work with JWT.

Installation

npm i @postnord/pretty-crypto

const myService = new CryptoMethods('xmEdy63WE2LCdvIJMdfwstD4e7aXINxG', 'jwfknefne', 'jwtsecret')

const raw = 'Hi there!'
const encrypted = await myService.encrypt(raw)
const decrypted = await myService.decrypt(encrypted)
expect(decrypted).toBe(raw)

const input = { k: 'v' }
const encoded = await myService.jwtEncode(input)
const decoded = await myService.jwtDecode(encoded)
expect(decoded).toEqual(input)

API

CryptoMethods(signingKey: string, ivKey: string, jwtKey: string)

Will initialize the class.

encrypt(rawInput: string): Promise<string>

Will return the encrypted string.

decrypt(encryptedInput: string): Promise<string>

Will return the decrypted string.

jwtEncode(input: object): Promise<string>

Will return the signed JWT string.

jwtDecode(input: string): Promise<object>

Will return the decoded JWT object