Search…
Crypto Module
Simple, fast crypto service. Import
1
import crypto from 'crypto';
Copied!

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
1
import crypto, { rsa } from 'crypto'
2
3
const apiKey = 'Lndee3dK9ZbMphlqQDtW9b',
4
encrypted = rsa.encrypt(
5
apiKey,
6
'Seymour R. Goff',
7
'base64'
8
)
9
10
return {
11
sha256: crypto.sha256("Seymour R. Goff"),
12
sha256Hmac: crypto.sha256Hmac("loose lips might sink ships", "Seymour R. Goff"),
13
encrypted: encrypted,
14
decrypted: rsa.decrypt(apiKey, encrypted)
15
}
Copied!
Crypto Example Response
1
{
2
"object": "result",
3
"data": {
4
"decrypted": "Seymour R. Goff",
5
"encrypted": "c8ZT8Cv4dH...xuR3BuTQ==",
6
"sha256": "bdd3e9c4cf...19200b8120",
7
"sha256Hmac": "4576a34032...7e7a52e139"
8
}
9
}
Copied!
Last modified 2mo ago