@postnord/pretty-crypto
v0.0.8
Published
Safely encrypt and decrypt asynchronous through Promises
Downloads
4,363
Maintainers
Keywords
Readme
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