Object built-in object

Object Cipher

Symmetric encryption algorithm object

Cipher objects belong to crypto Module, create:

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

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<this>Cipher|new Cipher()|name;keySize;ivSize;blockSize|paddingMode();encrypt();decrypt()] [object] <:- [Cipher] Cipher new Cipher() name keySize ivSize blockSize paddingMode() encrypt() decrypt() object toString() toJSON()

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, specify the working mode of 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, specify the working mode of 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 the current algorithm password

1
Buffer Cipher.encrypt(Buffer data) async;

Call parameters:

  • data: Buffer, Specify the data to be encrypted

Return result:

  • Buffer, Return the encrypted data

decrypt

Use the current algorithm password to decrypt the 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