@evokegroup/crypto
v2.0.0
Published
Crypto utilities
Downloads
5
Keywords
Readme
@evokegroup/crypto
Requires NodeJS 18+
Encryption
Classes
UnsupportedAlgorithmError
extends Error
InvalidInputLengthError
extends Error
Interfaces
EncryptOpts
| Property | Type |
| -------- | ---- |
| inputEncoding | BufferEncoding
|
| keyEncoding | BufferEncoding
|
| ivEncoding | BufferEncoding
|
| outputEncoding | BufferEncoding
|
| iterations | number
|
| hmac | string
|
| authTagLength | number
|
| authTagLocation | AuthTagLocation
|
DecryptOpts
extends EncryptOpts
| Property | Type |
| -------- | ---- |
| authTag | Buffer\|string
|
EncryptionResult
| Property | Type | Default | Description |
| -------- | ---- | ------- | ----------- |
| data | Buffer
, string
| | The encrypted data |
| authTag | Buffer
, string
| | The authentication tag |
Methods
decrypt
returns Promise<Buffer | string>
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | The encryption algorithm |
| data | Buffer
, string
| | The data to be encrypted |
| key | Buffer
, string
| | The encryption key |
| iv | Buffer
, string
| | The encryption IV |
| opts | DecryptOpts
| | |
| opts.inputEncoding | BufferEncoding
| utf8
| |
| opts.keyEncoding | BufferEncoding
| base64
| |
| opts.ivEncoding | BufferEncoding
| base64
| |
| opts.outputEncoding | BufferEncoding
| base64
| null
will cause the returned value to be a Buffer
. |
| opts.iterations | number
| 1000
| |
| opts.hmac | string
| sha256
| |
| opts.authTag | Buffer
, string
| | |
| opts.authTagLength | number
| 16
| |
| opts.authTagLocation | number
| APPEND
| |
decryptSync
returns Buffer | string
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | The encryption algorithm |
| data | Buffer
, string
| | The data to be encrypted |
| key | Buffer
, string
| | The encryption key |
| iv | Buffer
, string
| | The encryption IV |
| opts | DecryptOpts
| | |
| opts.inputEncoding | BufferEncoding
| utf8
| |
| opts.keyEncoding | BufferEncoding
| base64
| |
| opts.ivEncoding | BufferEncoding
| base64
| |
| opts.outputEncoding | BufferEncoding
| base64
| null
will cause the returned value to be a Buffer
. |
| opts.iterations | number
| 1000
| |
| opts.hmac | string
| sha256
| |
| opts.authTag | Buffer
, string
| | |
| opts.authTagLength | number
| 16
| |
| opts.authTagLocation | number
| APPEND
| |
encrypt
returns Promise<Buffer | string | EncryptionResult>
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | The encryption algorithm |
| data | Buffer
, string
| | The data to be encrypted |
| key | Buffer
, string
| | The encryption key |
| iv | Buffer
, string
| | The encryption IV |
| opts | EncryptOpts
| | |
| opts.inputEncoding | BufferEncoding
| utf8
| |
| opts.keyEncoding | BufferEncoding
| base64
| |
| opts.ivEncoding | BufferEncoding
| base64
| |
| opts.outputEncoding | BufferEncoding
| base64
| null
will cause the returned value to be a Buffer
. |
| opts.iterations | number
| 1000
| |
| opts.hmac | string
| sha256
| |
| opts.authTagLength | number
| 16
| |
| opts.authTagLocation | number
| APPEND
| |
encryptSync
returns Buffer | string | EncryptionResult
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | The encryption algorithm |
| data | Buffer
, string
| | The data to be encrypted |
| key | Buffer
, string
| | The encryption key |
| iv | Buffer
, string
| | The encryption IV |
| opts | EncryptOpts
| | |
| opts.inputEncoding | BufferEncoding
| utf8
| |
| opts.keyEncoding | BufferEncoding
| base64
| |
| opts.ivEncoding | BufferEncoding
| base64
| |
| opts.outputEncoding | BufferEncoding
| base64
| null
will cause the returned value to be a Buffer
. |
| opts.iterations | number
| 1000
| |
| opts.hmac | string
| sha256
| |
| opts.authTagLength | number
| 16
| |
| opts.authTagLocation | number
| APPEND
| |
generateRandomKey
returns Buffer | string
Generates a random key appropriate for the given encryption algorithm.
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | The encryption algorithm |
| outputEncoding | BufferEncoding
| | |
generateRandomIV
returns Buffer | string
Generates a random initialization vector appropriate for the given encryption algorithm.
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | The encryption algorithm |
| outputEncoding | BufferEncoding
| | |
getSupportedAlgorithms
returns string[]
Get a list of algorithms supported by this library.
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| scheme | string
| null
| Return algorithms only for the given encryption scheme (e.g. aes
, aria
, camellia
, des
, des3
) |
isSupportedAlgorithm
returns boolean
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | |
Hashing
Interfaces
HashOpts
| Property | Type |
| -------- | ---- |
| salt | Buffer
, string
|
| saltEncoding | BufferEncoding
|
| saltLocation | SaltLocation
|
| inputEncoding | BufferEncoding
|
| outputEncoding | BinaryToTextEncoding
|
Methods
calculateHash
returns Buffer | string
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| algorithm | string
| | The encryption algorithm |
| data | Buffer
, string
| | The data to be encrypted |
| opts | HashOpts
| | |
| opts.salt | Buffer
, string
| | |
| opts.saltEncoding | BufferEncoding
| base64
| |
| opts.saltLocation | SaltLocation
| APPEND
| |
| opts.inputEncoding | BufferEncoding
| utf8
| |
| opts.outputEncoding | BinaryToTextEncoding
| hex
| null
will cause the returned value to be a Buffer
. |
generateSalt
returns Buffer | string
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| saltLength | nmber
| 16
| |
| outputEncoding | BufferEncoding
| | |