Skip to content
James ZHANG edited this page Jan 16, 2022 · 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.

AesCbc

Aes encrypt/decrypt using aes-128-cbc algorithm with pkcs7padding.

Constants

utf8
base64
hex
16
aes-256-gcm
aes-256-ecb
aes-128-cbc
PKCS7

The PKCS#7 padding/unpadding implementation

Aes

Aes - Advanced Encryption Standard

Kind: global class

Aes.hex

Deprecated

Kind: static property of Aes
Properties

Name Type Description
hex string Alias of hex string

Aes.utf8

Deprecated

Kind: static property of Aes
Properties

Name Type Description
utf8 string Alias of utf8 string

Aes.base64

Deprecated

Kind: static property of Aes
Properties

Name Type Description
base64 string Alias of base64 string

Aes.BLOCK_SIZE

Deprecated

Kind: static property of Aes
Properties

Name Type Description
BLOCK_SIZE integer The aes block size

Aes.ALGO_AES_256_GCM

Deprecated

Kind: static property of Aes
Properties

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

Aes.ALGO_AES_256_ECB

Deprecated

Kind: static property of Aes
Properties

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

Aes.ALGO_AES_128_CBC

Deprecated

Kind: static property of Aes
Properties

Name Type Description
ALGO_AES_128_CBC string The aes-128-cbc algorithm

Aes.pkcs7

Kind: static property of Aes
Properties

Name Type Description
pkcs7 object The PKCS7 padding/unpadding container

pkcs7.padding(thing, [optional]) ⇒ Buffer

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

Kind: instance method of pkcs7
Summary: 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.
Returns: Buffer - - The PADDING tailed payload
See: rfc2315

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

pkcs7.unpadding(thing) ⇒ Buffer

unpadding

Kind: instance method of pkcs7
Returns: Buffer - - The PADDING wiped payload

Param Type Description
thing string | Buffer The input

Aes.encrypt() ⇒ string

Deprecated

Back compatible encrypt, shall removed future

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

Aes.decrypt() ⇒ string

Deprecated

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.

AesCbc

Aes encrypt/decrypt using aes-128-cbc algorithm with pkcs7padding.

Kind: global class

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

Encrypts plaintext.

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

Param Type Description
plaintext string Text to encode.
key string The secret key, 16 bytes string.
[iv] string The initialization vector, 16 bytes string.

AesCbc.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 AesCbc
Returns: string - Utf-8 plaintext.

Param Type Description
ciphertext string Base64-encoded ciphertext.
key string The secret key, 16 bytes string.
[iv] string The initialization vector, 16 bytes string.

utf8

Kind: global constant

base64

Kind: global constant

hex

Kind: global constant

16

Kind: global constant

aes-256-gcm

Kind: global constant

aes-256-ecb

Kind: global constant

aes-128-cbc

Kind: global constant

PKCS7

The PKCS#7 padding/unpadding implementation

Kind: global constant