Search
K

Crypto Module

Simple, fast crypto service. Import
import crypto from 'crypto';

Methods

md5(string)

Arguments
  • value (String) string to hash
Returns
  • value (String) hash value

md5Hmac(string, string)

Arguments
  • secret (String) secret key
  • value (String) string to hash
Returns
  • value (String) hash value

sha1(string)

Arguments
  • value (String) string to hash
Returns
  • value (String) hash value

sha1Hmac(string, string)

Arguments
  • secret (String) secret key
  • value (String) string to hash
Returns
  • value (String) hash value

sha256(string)

Arguments
  • value (String) string to hash
Returns
  • value (String) hash value

sha256Hmac(string, string)

Arguments
  • secret (String) secret key
  • value (String) string to hash
Returns
  • value (String) hash value

sha512(string)

Arguments
  • value (String) string to hash
Returns
  • value (String) hash value

sha512Hmac(string, string)

Arguments
  • secret (String) secret key
  • value (String) string to hash
Returns
  • value (String) hash value

rsa.encrypt(apiKey, payload, outputEncoding=buffer, inputEncoding=utf8)

Encrypt a JSON object or a string using an app's RSA public key
Arguments
  • apiKey (String) The app api key that holds the key pair
  • payload (String|Object) string or JSON object to encrypt
  • outputEncoding (String=buffer) Support output encodings are hex, base64, buffer and binary
  • inputEncoding (String=utf8) Supported input encodings are hex, base64 and utf8
Returns
  • value (Buffer|String) encrypted value

rsa.decrypt(apiKey, payload, outputEncoding=utf8)

Decrypt a buffer or base64 encoded string app's RSA private key
Arguments
  • apiKey (String) The app api key that holds the key pair
  • payload (String|Buffer) string or buffer to decrypt
  • outputEncoding (String=utf8) Support output encodings are hex, base64, buffer, binary, utf8 and json. If json is specified, decrypt will parse the resulting string..
Returns
  • value (String|Object) decrypted value

Examples

Crypto Example
import crypto, { rsa } from 'crypto'
const apiKey = 'Lndee3dK9ZbMphlqQDtW9b',
encrypted = rsa.encrypt(
apiKey,
'Seymour R. Goff',
'base64'
)
return {
sha256: crypto.sha256("Seymour R. Goff"),
sha256Hmac: crypto.sha256Hmac("loose lips might sink ships", "Seymour R. Goff"),
encrypted: encrypted,
decrypted: rsa.decrypt(apiKey, encrypted)
}
Crypto Example Response
{
"object": "result",
"data": {
"decrypted": "Seymour R. Goff",
"encrypted": "c8ZT8Cv4dH...xuR3BuTQ==",
"sha256": "bdd3e9c4cf...19200b8120",
"sha256Hmac": "4576a34032...7e7a52e139"
}
}