Skip to content
James ZHANG edited this page Mar 20, 2021 · 5 revisions

Classes

Aes

Aes - Advanced Encryption Standard

AesGcm

Aes encrypt/decrypt using aes-256-gcm algorithm with AAD.

AesEcb

Aes encrypt/decrypt using aes-256-ecb algorithm with pkcs7padding.

Functions

padding(thing, [optional])Buffer

padding, 32 bytes/256 bits secret key may optional need the last block.

unpadding(thing)Buffer

unpadding

Aes

Aes - Advanced Encryption Standard

Kind: global class

Aes.hex

Kind: static property of Aes
Properties

Name Type Description
hex string Alias of hex string

Aes.utf8

Kind: static property of Aes
Properties

Name Type Description
utf8 string Alias of utf8 string

Aes.base64

Kind: static property of Aes
Properties

Name Type Description
base64 string Alias of base64 string

Aes.BLOCK_SIZE

Kind: static property of Aes
Properties

Name Type Description
BLOCK_SIZE integer The aes block size

Aes.ALGO_AES_256_GCM

Kind: static property of Aes
Properties

Name Type Description
ALGO_AES_256_GCM string The aes-256-gcm algorithm

Aes.ALGO_AES_256_ECB

Kind: static property of Aes
Properties

Name Type Description
ALGO_AES_256_ECB string The aes-256-ecb algorithm

Aes.pkcs7

Kind: static property of Aes
Properties

Name Type Description
pkcs7 object The PKCS7 padding/unpadding container

Aes.encrypt() ⇒ string

Back compatible encrypt, shall removed future

Kind: static method of Aes
Returns: string - Base64-encoded ciphertext.

Aes.decrypt() ⇒ string

Back compatible decrypt, shall removed future

Kind: static method of Aes
Returns: string - Utf-8 plaintext.

AesGcm

Aes encrypt/decrypt using aes-256-gcm algorithm with AAD.

Kind: global class

AesGcm.encrypt(iv, key, plaintext, aad) ⇒ string

Encrypts plaintext.

Kind: static method of AesGcm
Returns: string - Base64-encoded ciphertext.

Param Type Description
iv string The initialization vector, 16 bytes string.
key string The secret key, 32 bytes string.
plaintext string Text to encode.
aad string The additional authenticated data, maybe empty string.

AesGcm.decrypt(iv, key, ciphertext, aad) ⇒ string

Decrypts ciphertext.

Kind: static method of AesGcm
Returns: string - Utf-8 plaintext.

Param Type Description
iv string The initialization vector, 16 bytes string.
key string The secret key, 32 bytes string.
ciphertext string Base64-encoded ciphertext.
aad string The additional authenticated data, maybe empty string.

AesEcb

Aes encrypt/decrypt using aes-256-ecb algorithm with pkcs7padding.

Kind: global class

AesEcb.encrypt(plaintext, key, [iv]) ⇒ string

Encrypts plaintext.

Kind: static method of AesEcb
Returns: string - Base64-encoded ciphertext.

Param Type Default Description
plaintext string Text to encode.
key string The secret key, 32 bytes string.
[iv] string null The initialization vector, default is null.

AesEcb.decrypt(ciphertext, key, [iv]) ⇒ string

Decrypts ciphertext. Notes here: While turns the setAutoPadding(true), it works well. Beause the pkcs5padding is a subset of pkcs7padding. Let's unpadding self.

Kind: static method of AesEcb
Returns: string - Utf-8 plaintext.

Param Type Default Description
ciphertext string Base64-encoded ciphertext.
key string The secret key, 32 bytes string.
[iv] string null The initialization vector, default is null.

padding(thing, [optional]) ⇒ Buffer

padding, 32 bytes/256 bits secret key may optional need the last block.

Kind: global function
Returns: Buffer - - The PADDING tailed payload
See: https://tools.ietf.org/html/rfc2315#section-10.3 The padding can be removed unambiguously since all input is padded and no padding string is a suffix of another. This padding method is well-defined if and only if k < 256; methods for larger k are an open issue for further study.

Param Type Default Description
thing string | Buffer The input
[optional] boolean true The flag for the last padding

unpadding(thing) ⇒ Buffer

unpadding

Kind: global function
Returns: Buffer - - The PADDING wiped payload

Param Type Description
thing string | Buffer The input
Clone this wiki locally