node-cryptography
About
Simplified functions for nodejs cryptography.
Usage
Functions
cryptography.encrypt(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
options.callback
<Function>
Returns a promise which is resolved with encrypted string. If a callback is passed it is called with encrypted string.
cryptography.encryptSync(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
Synchronous encrypt(). Returns encrypted string.
cryptography.decrypt(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
options.callback
<Function>
Returns a promise which is resolved with decrypted string. If a callback is passed it is called with decrypted string.
cryptography.decryptSync(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
Synchronous decrypt(). Returns decrypted string.
cryptography.hmac(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
options.callback
<Function>
Returns a promise which is resolved with hashed string. If a callback is passed it is called with hashed string.
cryptography.hmacSync(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
Synchronous hmac(). Returns hashed string.
cryptography.hash(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
options.callback
<Function>
Returns a promise which is resolved with hashed string. If a callback is passed it is called with hashed string.
cryptography.hashSync(options)
options
<Object>
|<string>
options.key
<string>
options.algorithm
<string>
options.encoding
<string>
options.data
<string>
Synchronous hash(). Returns hashed string.
cryptography.randomBytes(options)
options
<Object>
|<Number>
options.size
<Number>
options.encoding
<string>
options.callback
<Function>
Returns a promise which is resolved with random bytes string. If a callback is passed it is called with random bytes string.
cryptography.randomBytesSync(options)
Synchronous randomBytes(). Returns random bytes string.
Example with promise
const cryptography = ; // Set defaultscryptographydefaultskey = "password";cryptographydefaultsencryptionAlgorithm = "aes192";cryptographydefaultsencoding = "hex"; // Use defaultscryptography; // Override defaults for one callcryptography;
Example with callback
const cryptography = ;var { iferror // Error occurred return; console;};var { iferror // Error occurred return; cryptography;}; cryptography;
Example with synchronous
const cryptography = ; try var encrypted = cryptography; var decrypted = cryptography;catcherror // Error occurred return; console;