Object built-in object

Object Cipher

Symmetric Cryptography Object

Cipher objects belong to the crypto module and are created:

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

Inheritance

Constructor

Cipher

Cipher constructor, for ARC4 initialization only

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

Call parameters:

  • provider : Integer, specify the 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 the encryption algorithm
  • mode : Integer, specifies the block cipher working mode
  • 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 the encryption algorithm
  • mode : Integer, specifies the block cipher working mode
  • key : Buffer , specify the encryption and decryption password
  • iv : Buffer , specify the initial vector

Member attributes

name

String, returns the name of the current algorithm

1
readonly String Cipher.name;

keySize

Integer, returns the current algorithm password length, in bits

1
readonly Integer Cipher.keySize;

ivSize

Integer, returns the initial vector length 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 fill mode, the default is PADDING_PKCS7

encrypt

Encrypt data using current algorithm password

1
Buffer Cipher.encrypt(Buffer data) async;

Call parameters:

  • data : Buffer , specifies the data to be encrypted

Returns the result:

  • Buffer , return the encrypted data

decrypt

Decrypt data using current algorithm password

1
Buffer Cipher.decrypt(Buffer data) async;

Call parameters:

  • data : Buffer , specifies the data to be decrypted

Returns the result:

  • Buffer , return the decrypted data

toString

Returns a string representation of the object, usually "[Native Object]". Objects can be reimplemented according to their own characteristics

1
String Cipher.toString();

Returns the result:

  • String , returns a string representation of the object

toJSON

Returns a JSON representation of the object, typically returning a collection of readable properties defined by the object

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

Call parameters:

  • key : String, unused

Returns the result:

  • Value , returns a value containing a JSON serializable