wilton.js  v202103141
 All Namespaces Functions
Functions
crypto Namespace Reference

wilton/crypto
Cryptography operations. More...

Functions

Object createCryptKey (String secret, Function|Undefined callback)
 Create crypt params from the specified string.
Undefined decryptFile (Object options, Function|Undefined callback)
 AES decryption.
Undefined encryptFile (Object options, Function|Undefined callback)
 AES encryption.
String hashFile (Object options, Function|Undefined callback)
 Compute SHA256 sum of a file.

Detailed Description

This module provides access to cryptography operations: encryption and hash sum computation. Processing is done on files without loading all their content into memory.

Usage example:

// compute SHA-256 from file contents
var sha256 = crypto.hashFile({
filePath: plain
});
// create encryption key and init vector
// from arbitrary secret string
var pars = crypto.createCryptKey("mysecret");
// encrypt file
crypto.encryptFile({
filePath: "path/to/plain.txt",
destFilePath: "path/to/encrypted.dat",
cryptKey: pars.cryptKey,
initVec: pars.initVec
});
// decrypt file
crypto.decryptFile({
filePath: "path/to/encrypted.dat",
destFilePath: "path/to/decrypted.txt",
cryptKey: pars.cryptKey,
initVec: pars.initVec
});

Function Documentation

Object crypto::createCryptKey ( String  secret,
Function|Undefined  callback 
)

Deterministically creates encryption key and initialization vector from the specified input string.

Parameters
secretString input secret string to create crypt params
callbackFunction|Undefined callback to receive result or error
Returns
Object with the following fields:
  • cryptKey String encryption key in hexadecimal
  • initVec String initialization vector in hexadecimal
Undefined crypto::decryptFile ( Object  options,
Function|Undefined  callback 
)

Decrypts specified file using AES with specifief encryption key and initialization vector.

Key an IV may be created with createCryptKey.

Results are written to the specified destination path.

Parameters
optionsObject configuration object, see possible options below
callbackFunction|Undefined callback to receive result or error
Returns
Undefined

Options

  • filePath String path to the file to decrypt
  • desfilePath String path to the file to write decryption results into
  • cryptKey String encryption key in hexadecimal, must be 32 bytes long
  • initVec String init vector in hexadecimal, must be 16 bytes long
Undefined crypto::encryptFile ( Object  options,
Function|Undefined  callback 
)

Encrypts specified file using AES with specifief encryption key and initialization vector.

Key an IV may be created with createCryptKey.

Results are written to the specified destination path.

Parameters
optionsObject configuration object, see possible options below
callbackFunction|Undefined callback to receive result or error
Returns
Undefined

Options

  • filePath String path to the file to encrypt
  • desfilePath String path to the file to write encryption results into
  • cryptKey String encryption key in hexadecimal, must be 32 bytes long
  • initVec String init vector in hexadecimal, must be 16 bytes long
String crypto::hashFile ( Object  options,
Function|Undefined  callback 
)

Computes SHA256 hash sum from the contents of a specified file. Hash sum value returned as a hexadecimal string.

Parameters
optionsObject configuration object, see possible options below
callbackFunction|Undefined callback to receive result or error
Returns
String

Options

  • filePath String path to the file to compute SHA256