Simple and flexible implementation Crypto Module functions to hash/ encrypt/ decrypt content and get SHA or other algorithm hashes of text or any data
npm install hasher-apisSimpler flexible implementation Crypto Module functions to hash/ encrypt/ decrypt content and get SHA or other algorithm hashes of text or any data
Find the demos in the demos folder
You can find details about used crypto algorithm details in the nodejs crypto, cipher, decipher, diffiehellman, hmac, hash, and other docs here
``
var hasher = require("hasher-apis");
hasher._createSHAHash(data="texter data", algorithm = "sha256", digest="base64", options = { logger: console.log })
hasher.createSHA(data="texter data", algorithm = "sha256", digest="base64", options = { logger: console.log })
`
`
import { default as _createSHAHash, createSHA } as "hasher-apis";
_createSHAHash(data="texter data", algorithm = "sha256", digest="base64", options = { logger: console.log })
createSHA(data="texter data", algorithm = "sha256", digest="base64", options = { logger: console.log })
`
`
var hasher = import("hasher-apis");
hasher._createSHAHash(data="texter data", algorithm = "sha256", digest="base64", options = { logger: console.log })
hasher.createSHA(data="texter data", algorithm = "sha256", digest="base64", options = { logger: console.log })
`
* ##### Data or Content Based Methods
- hashContent, dehashContent, encryptWithKey, decryptWithKey
* ##### File Based Methods
- hashFile, dehashFile, verifyHashedFile, verifyFile, encrypt, decrypt, createSign, createSignVerify
* ##### Keys or Hash or Other Based Methods
- createSHA, verifySHA, verifyFileContent, getCiphers, getHashes, getDiffieHellman, getFips, getRandomValues, getConstants, getSymbolsList, genKeyPair, dumpKeyFile
Create an encrytion using a content using salt and algorithms
Usage: hashContent(data, salt, algorithm, keyAlgorithm, digest, options)
Usage: hashContent(data, salt)
``
/**
*
@param {} data
@param {} salt
* @param {string} [algorithm="aes-256-ctr"]
* [default: "aes-256-ctr"]
* [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Create an decryption of encrypted data using salt and algorithms
Usage: dehashContent(hashdata, salt, algorithm, keyAlgorithm, digest, options)
Usage: dehashContent(hashdata, salt)
``
/**
*
@param {} hashdata
@param {} salt
* @param {string} [algorithm="aes-256-ctr"]
* [default: "aes-256-ctr"]
* [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Usage: encryptWithKey(data, options)
``
/**
* encryptWithKey
*
@param {} [options] < { [publicKey | publicKeyPath], padding, algorithm ) } >
@return {}
*/
Usage: decryptWithKey(hashdata, options)
``
/**
*
*
@param {} hashdata
@param {} [options] < { [privateKey | privateKeyPath], padding, algorithm ) } >
@return {}
*/
Create an encrytion of a file using salt and algorithms
Usage: hashFile(remotePath, remoteDestPath, salt, algorithm, keyAlgorithm, digest, options)
Usage: hashFile(remotePath, remoteDestPath, salt)
``
/**
*
@param {} remotePath
@param {} remoteDestPath
@param {} salt
* @param {string} [algorithm="aes-256-ctr"]
* [default: "aes-256-ctr"]
* [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Create an decryption of encrypted file using salt and algorithms
Usage: dehashFile(remotePath, remoteDestPath, salt, algorithm, keyAlgorithm, digest, options)
Usage: dehashFile(remotePath, remoteDestPath, salt)
``
/**
*
@param {} remotePath
@param {} remoteDestPath
@param {} salt
* @param {string} [algorithm="aes-256-ctr"]
* [default: "aes-256-ctr"]
* [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Create an encrytion of a file using salt and algorithms
Usage: fileHashFromContent(remotePath, content, salt, algorithm, keyAlgorithm, digest, options)
Usage: fileHashFromContent(remotePath, content, salt)
``
/**
* fileHashFromContent
* file uses _fileContentHash function
*
@param {} remoteDestPath
@param {} data
@param {} salt
* @param {string} [algorithm="aes-256-ctr"] [default: "aes-256-ctr"] [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"] [default: "SHA256"] [options: use function getHashes]
* @param {string} [digest="base64"] [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options [default: { logger: console.log }] [options: logger function]
@return {}
*/
Create an encrytion of a file using salt and algorithms
Usage: fileDeHashContent(remoteDestPath, salt, algorithm, keyAlgorithm, digest, options)
Usage: fileDeHashContent(remoteDestPath, salt)
`
/**
* fileDeHashContent
* file uses _fileContentDeHash
*
@param {} remoteDestPath
@param {} salt
* @param {string} [algorithm="aes-256-ctr"] [default: "aes-256-ctr"] [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"] [default: "SHA256"] [options: use function getHashes]
* @param {string} [digest="base64"] [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options [default: { logger: console.log }] [options: logger function]
@return {}
*/
`
Create an encrytion of a file using salt and algorithms
Usage: fileDeHashLoadContent(remoteDestPath, salt, algorithm, keyAlgorithm, digest, options)
Usage: fileDeHashLoadContent(remoteDestPath, salt)
`
/**
* fileDeHashLoadContent
* file uses _fileContentDeHash
*
@param {} remoteDestPath
@param {} salt
* @param {string} [algorithm="aes-256-ctr"]
* @param {string} [keyAlgorithm="sha256"]
* @param {string} [digest="base64"]
@param {} [options={ logger: console.log }]
@return {}
*/
`
Verify a content data using hash provided
Usage: verifyFileContent(data, hashToCheck, algorithm, digest, options)
Usage: verifyFileContent(data, hashToCheck)
``
/**
*
@param {} data
@param {} hashToCheck
* @param {string} [algorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Verify a file data using hash provided
Usage: verifyHashedFile(remotePath, hashToCheck, algorithm, digest, options)
Usage: verifyHashedFile(remotePath, hashToCheck)
``
/**
*
@param {} remotePath
@param {} hashToCheck
* @param {string} [algorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Verify a file data using checksum provided - market standards
Usage: verifyFile(remotePath, checksum, algorithm, digest, options)
Usage: verifyFile(remotePath, checksum)
``
/**
*
@param {} remotePath
@param {} checksum
* @param {string} [algorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Encrypt a file
Usage: encrypt(remotePath, remoteDestPath, algorithm, keyAlgorithm, digest, keyOptions, options)
Usage: encrypt(remotePath, remoteDestPath)
``
/**
*
*
@param {} remotePath
@param {} remoteDestPath
* @param {string} [algorithm="aes-256-ctr"]
* [default: "aes-256-ctr"]
* [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { modulusLength: 2048 }]
@return {} Returns Object: { publicKey, privateKey, encrypted }
*
*/
Decrypt a file
Usage: decrypt(remotePath, remoteDestPath, privateKey, algorithm, keyAlgorithm, digest, options)
Usage: decrypt(remotePath, remoteDestPath, privateKey)
``
/**
*
@param {} remotePath
@param {} remoteDestPath
@param {} privateKey
* @param {string} [algorithm="aes-256-ctr"]
* [default: "aes-256-ctr"]
* [options: use function getCiphers]
* @param {string} [keyAlgorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { modulusLength: 2048 }]
@return {}
@param {}
* [options={ modulusLength: 2048 }]
@return {} Returns Object: { decrypted }
*
*/
Sign a Data
Usage: createSign(data, algorithm, base, keyGenType, keyOptions, options, encryptType)
Usage: createSign(data)
``
/**
*
@param {} data
@param {} algorithm
* [default: "SHA256"]
* [options: use function getHashes]
@param {} base
* [default: "hex"]
* [options: ]
@param {} keyGenType
* [default: "rsa"]
* [options: 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh']
@param {} keyOptions
* [default: For createSign & publicEncrypt: { modulusLength: 2048 }]
@param {} options
* [default: For createSign: { modulusLength: 2048 }, For publicEncrypt: { padding: crypto.constants.RSA_PKCS1_PSS_PADDING}]
@param {} encryptType
* [default: "createSign"]
* [options: createSign, publicEncrypt]
@return {} Returns Object: { publicKey, privateKey, signature }
*
*/
Verify a Signed Data
Usage: createSignVerify(data, signature, publicKey, algorithm, base, options, encryptType)
Usage: createSignVerify(data, signature, publicKey)
``
/**
*
@param {} data
@param {} signature
@param {} publicKey
@param {} algorithm
* [default: "SHA256"]
* [options: use function getHashes]
@param {} base
* [default: "hex"]
* [options: ]
@param {} options
* [default: For createSign: { modulusLength: 2048 }, For publicEncrypt: { padding: crypto.constants.RSA_PKCS1_PSS_PADDING }]
@param {} encryptType
* [default: "createSign"]
* [options: createSign, publicEncrypt]
@return {} Boolean
*
*/
Create an Hash with algorithms like SHA using a data
Usage: createSHA(data, algorithm , digest, options)
Usage: createSHA(data)
``
/**
*
@param {} data
* @param {string} [algorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Verify an data using hash provided
Usage: verifySHA(data, hashToCheck, algorithm, digest, options)
Usage: verifySHA(data, hashToCheck)
``
/**
*
*
@param {} data
@param {} hashToCheck
* @param {string} [algorithm="sha256"]
* [default: "SHA256"]
* [options: use function getHashes]
* @param {string} [digest="base64"]
* [default: "base64"]
* [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options
* [default: { logger: console.log }]
* [options: logger function]
@return {}
*
*/
Usage: verifyFileContentHash(data, hashToCheck, algorithm, digest, options)
``
/**
*
*
@param {} data
@param {} hashToCheck
* @param {string} [algorithm="sha256"] [default: "SHA256"] [options: use function getHashes]
* @param {string} [digest="base64"] [options: ['ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex']]
@param {} options [default: { logger: console.log }] [options: logger function]
@return {}
*/
Create a Key Pair - public and private using key generator type and options for key generation
Usage: _genKeyPair(keyGenType, options)
Usage: _genKeyPair()
``
/**
*
* @param {string} [keyGenType="rsa"]
* [default: "rsa"]
* [options: 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh']
@param {}
* [default: { modulusLength: 2048 }]
* [options={ modulusLength: 2048 }]
@return {} Returns Object { publicKey, privateKey }
*
*/
Get list of Ciphers supported by Node Crypto Module
Usage: getCiphers()
``
/**
*
@return {} Returns list of Ciphers in Crypto Module
*
*/
Get list of Hashes supported by Node Crypto Module
Usage: getHashes()
``
/**
*
@return {} Returns list of Hash Algorithms in Crypto Module
*
*/
Usage: getDiffieHellman(groupName)
``
/**
* getDiffieHellman
*
@param {} groupName
@return {[]}
*/
Usage: getFips()
``
/**
* getFips
*
@return {[]}
*/
Usage: getRandomValues(typedArray)
``
/**
* getRandomValues
*
@param {} typedArray
@return {[]}
*/
Usage: getConstants(constantname)
``
/**
* List of constants in crypto
*
@param {} constantname
@return {}
*/
Create an public key and private key using genKeyPair or \_genKeyPair functions
_genKeyPair(keyGenType = "rsa", options)
``
/**
* genKeyPair
*
* @param {string} [keyGenType="rsa"] [default: "rsa"] [options: 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh']
@param {} [options={ modulusLength: 2048 }] [default: { modulusLength: 2048 }]
@return {}
*/
Usage: dumpKeyFile(filename, key, format, base)
```
/**
* dumpKeyFile
*
@param {} filename
@param {} key
* @param {string} [format="pem"]
* @param {string} [base="hex"]
*/
Details in todo file
Contributions, Feature Improvements, Bugs, and Issues are invited. raising an issue