Simple KMS Cryptor
Simple cryptor library for encrypting object using AWS KMS key
Usage Example
Prepare the config
The config is compatible directly with the AWS.KMS options as specified here:
Example of config:
let config = region: '<your aws region here>' accessKeyId: '<your aws access key id here>' secretAccessKey: '<your aws secret access key>' kms: KeyId: '<kms key ARN or KeyId>'
Creating instance
const KMSCrypt = ; let kmscrypt = config;
Encrypting object
encrypt
method will return a promise
- Encrypting
plaintext
to a byte array
let plaintext = 'secret text';kmscrypt
- Encrypting
plaintext
to a byte array
let plaintext = 'secret text';kmscrypt
Decrypting object
decrypt
method will return a promise
- If
ciphertext
is a byte array
kmscrypt
- If
ciphertext
is base64 encoded
kmscrypt
Methods
encrypt(plaintext, encryptionType) => Promise
plaintext
is the object to be encrypted. Supported format:string
,object
,number
encryptionType
: base64 | binary (default)
decrypt(ciphertext, cipherType) => Promise
ciphertext
is the encrypted data formatted as binary or base64cipherType
is the type ofciphertext
which can be base64 or binary