-
-
Notifications
You must be signed in to change notification settings - Fork 44
aes.js
- Aes
-
Aes - Advanced Encryption Standard
- AesGcm
-
Aes encrypt/decrypt using
aes-256-gcmalgorithm withAAD. - AesEcb
-
Aes encrypt/decrypt using
aes-256-ecbalgorithm with pkcs7padding. - AesCbc
-
Aes encrypt/decrypt using
aes-128-cbcalgorithm with pkcs7padding.
- utf8
- base64
- hex
- 16
- aes-256-gcm
- aes-256-ecb
- aes-128-cbc
- PKCS7
-
The PKCS#7 padding/unpadding implementation
Aes - Advanced Encryption Standard
Kind: global class
-
Aes
.hex.utf8.base64.BLOCK_SIZE.ALGO_AES_256_GCM.ALGO_AES_256_ECB.ALGO_AES_128_CBC-
.pkcs7
-
.padding(thing, [optional]) ⇒
Buffer -
.unpadding(thing) ⇒
Buffer
-
.padding(thing, [optional]) ⇒
.encrypt() ⇒string.decrypt() ⇒string
Deprecated
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| hex | string |
Alias of hex string |
Deprecated
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| utf8 | string |
Alias of utf8 string |
Deprecated
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| base64 | string |
Alias of base64 string |
Deprecated
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| BLOCK_SIZE | integer |
The aes block size |
Deprecated
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| ALGO_AES_256_GCM | string |
The aes-256-gcm algorithm |
Deprecated
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| ALGO_AES_256_ECB | string |
The aes-256-ecb algorithm |
Deprecated
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| ALGO_AES_128_CBC | string |
The aes-128-cbc algorithm |
Kind: static property of Aes
Properties
| Name | Type | Description |
|---|---|---|
| pkcs7 | object |
The PKCS7 padding/unpadding container |
-
.pkcs7
-
.padding(thing, [optional]) ⇒
Buffer -
.unpadding(thing) ⇒
Buffer
-
.padding(thing, [optional]) ⇒
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
|
unpadding
Kind: instance method of pkcs7
Returns: Buffer - - The PADDING wiped payload
| Param | Type | Description |
|---|---|---|
| thing |
string | Buffer
|
The input |
Deprecated
Back compatible encrypt, shall removed future
Kind: static method of Aes
Returns: string - Base64-encoded ciphertext.
Deprecated
Back compatible decrypt, shall removed future
Kind: static method of Aes
Returns: string - Utf-8 plaintext.
Aes encrypt/decrypt using aes-256-gcm algorithm with AAD.
Kind: global class
-
AesGcm
-
.encrypt(iv, key, plaintext, aad) ⇒
string -
.decrypt(iv, key, ciphertext, aad) ⇒
string
-
.encrypt(iv, key, plaintext, aad) ⇒
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. |
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. |
Aes encrypt/decrypt using aes-256-ecb algorithm with pkcs7padding.
Kind: global class
-
AesEcb
-
.encrypt(plaintext, key, [iv]) ⇒
string -
.decrypt(ciphertext, key, [iv]) ⇒
string
-
.encrypt(plaintext, key, [iv]) ⇒
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. |
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. |
Aes encrypt/decrypt using aes-128-cbc algorithm with pkcs7padding.
Kind: global class
-
AesCbc
-
.encrypt(plaintext, key, [iv]) ⇒
string -
.decrypt(ciphertext, key, [iv]) ⇒
string
-
.encrypt(plaintext, key, [iv]) ⇒
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. |
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. |
The PKCS#7 padding/unpadding implementation
Kind: global constant