@am92/kms
v3.0.3
Published
Key Management Service
Downloads
23
Readme
@am92/kms
This package provides Key Management related functionalities using either Node Crypto or AWS KMS. It provides the following functionalities:
- Generating Encryption Key for Symmetric and Asymmetric Algorithms
- Encrypting and Decrypting data
For full documentation, visit here.
Table of Content
- Installation
- Environment Variables
- Creating an Instance
- Self-managed Config
- Contributors
- Resources
- License
Installation
npm install --save @am92/kmsEnvironment Variables
The following environment variables need to be set to work with this package:
##### KMS Config
export KMS_ENABLED=
export KMS_TYPE=''
export KMS_KEY_SPEC=''
export KMS_KEY_PAIR_SPEC=''
export KMS_KEY_FORMAT=''
export KMS_PLAIN_TEXT_FORMAT=''
export KMS_CIPHER_TEXT_FORMAT=''
export KMS_MASTER_KEY_HEX=''
export KMS_MASTER_IV_HEX=''
export KMS_AWS_REGION=''
export KMS_AWS_KEY_ID=''| Variable Name | Required | Default | Description |
| ----------------------- | -------- | ------------------------ | --------------------------------------------------------------------------- |
| KMS_ENABLED | No | false | Enables/Disables KMS functionality |
| KMS_TYPE | No* | - | Type of KMS to use. Possible values: NODE, AWS |
| KMS_KEY_SPEC | No | AES_256 | Specification for symmetric key generation |
| KMS_KEY_PAIR_SPEC | No | RSA_2048 | Specification for asymmetric key pair generation |
| KMS_KEY_FORMAT | No | base64 | Format for generated keys |
| KMS_PLAIN_TEXT_FORMAT | No | base64 | Format for plain text data |
| KMS_CIPHER_TEXT_FORMAT| No | base64 | Format for encrypted data |
| KMS_MASTER_KEY_HEX | No | 0000000000000000000000000000000000000000000000000000000000000000 | Master key in hex format for Node Crypto |
| KMS_MASTER_IV_HEX | No | 00000000000000000000000000000000 | Master IV in hex format for Node Crypto |
| KMS_AWS_REGION | No | ap-south-1 | AWS region for KMS operations |
| KMS_AWS_KEY_ID | No** | - | AWS KMS key ID for encryption/decryption |
Note:
- * - Required if
KMS_ENABLEDis set totrue. - ** - Required if
KMS_TYPEis set toAWS.
Creating an Instance
import { generateKmsInstance } from '@am92/kms'
const kms = generateKmsInstance()
export default kmsSelf-managed Config
If you wish to pass your custom 'config' for Kms, then you can avoid setting any environment variables defined above and pass your own config as follows:
import { generateKmsInstance } from '@am92/kms'
const config = {
KMS_TYPE: 'NODE'
}
const kms = generateKmsInstance(config)
export default kms