Object built-in object

Object Cipher

Symmetric encryption algorithm object

The Cipher object belongs to the crypto module and is created:

1
var c = new crypto.Cipher(crypto.AES, crypto.ECB, ...);

Inheritance

Constructor

Cipher

Cipher constructor, only used for ARC4 initialization

1 2
new Cipher(Integer provider, Buffer key);

Call parameters:

  • provider : Integer, specify encryption algorithm
  • key : Buffer , specify the encryption and decryption password

Cipher constructor

1 2 3
new Cipher(Integer provider, Integer mode, Buffer key);

Call parameters:

  • provider : Integer, specify encryption algorithm
  • mode : Integer, specifies the working mode of the block cipher
  • key : Buffer , specify the encryption and decryption password

Cipher constructor

1 2 3 4
new Cipher(Integer provider, Integer mode, Buffer key, Buffer iv);

Call parameters:

  • provider : Integer, specify encryption algorithm
  • mode : Integer, specifies the working mode of the block cipher
  • key : Buffer , specify the encryption and decryption password
  • iv : Buffer , specify the initial vector

Member attributes

name

String, returns the current algorithm name

1
readonly String Cipher.name;

keySize

Integer, returns the length of the current algorithm password, in bits

1
readonly Integer Cipher.keySize;

ivSize

Integer, returns the length of the initial vector of the current algorithm, in bytes

1
readonly Integer Cipher.ivSize;

blockSize

Integer, returns the length of the current algorithm data block in bytes

1
readonly Integer Cipher.blockSize;

Member function

paddingMode

Use fill mode

1
Cipher.paddingMode(Integer mode);

Call parameters:

  • mode : Integer, specify the padding mode, the default is PADDING_PKCS7

encrypt

Encrypt data using current algorithm password

1
Buffer Cipher.encrypt(Buffer data) async;

Call parameters:

  • data : Buffer , specify the data to be encrypted

Return result:

  • Buffer , returns the encrypted data

decrypt

Use current algorithm password to decrypt data

1
Buffer Cipher.decrypt(Buffer data) async;

Call parameters:

  • data : Buffer , specify the data to be decrypted

Return result:

  • Buffer , return the decrypted data

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String Cipher.toString();

Return result:

  • String , returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value Cipher.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable