Cryptography API
Connector functions JS API guide for crypto utility
This file provides methods for different crypto utilities using crypt global object.
Encrypt and decrypt messages with AES algorithms
The crypt.aes global object provides all the functions for encryption and decryption using the AES algorithm.
These JavaScript functions use the cipher algorithm identifier required by the Java method javax.crypto.Cipher.getInstance(algorithm), composed of {CipherName}/{cipherMode}/{CipherPadding}. Some examples are:
- AES/CBC/NoPadding
- AES/CBC/PKCS5Padding
- AES/ECB/NoPadding
- AES/ECB/PKCS5Padding
- AES/GCM/NoPadding
Data hashing
The crypt.hmac global object provides functions for hashing data.
AES JS API
crypt.aes.encrypt(algorithm, key, ivParameterSpec, data)
Encrypt the data using the selected AES algorithm with the provided shared key.
Kind: global function
Returns: Uint8Array
| Param | Type | Description |
|---|---|---|
| algorithm | string |
algorithm identifier, as required in java javax.crypto.Cipher.getInstance(algorithm). For example: AES/CBC/PKCS5Padding |
| key | Uint8Array |
key used to encrypt the data. In AES algorithms. The key size must match the selected algorithm. For example, AES algorithms support keys of 16 bytes (AES-128), 24 bytes (AES-192), or 32 bytes (AES-256). |
| ivParam | Uint8Array |
Initialization vector (IV) used in encryption. Only allowed or required depending on the selected algorithm. |
| data | Uint8Array |
data to be encoded |
crypt.aes.decrypt(algorithm, key, ivParameterSpec, data)
Decrypt the data using the selected AES algorithm with the provided shared key.
Kind: global function
Returns: Uint8Array
| Param | Type | Description |
|---|---|---|
| algorithm | string |
algorithm identifier, as required in java javax.crypto.Cipher.getInstance(algorithm). For example: AES/CBC/PKCS5Padding |
| key | Uint8Array |
key used to decrypt the data. In AES algorithms. The key size must match the selected algorithm. For example, AES algorithms support keys of 16 bytes (AES-128), 24 bytes (AES-192), or 32 bytes (AES-256). |
| ivParam | Uint8Array |
Initialization vector (IV) used in encryption. Only allowed or required depending on the selected algorithm. |
| data | Uint8Array |
encoded data to be decrypted |
HMAC JS API
Following functions apply some hashing function with specified key to specified data. In all cases, the result is a JSON with following structure:
| Param | Type | Description |
|---|---|---|
| error | string |
It will be null if hashing finishes correctly. If hashing fails, exception message will be indicated. |
| result | Uint8Array |
Obtained hash. If the hash function is applied correctly, byte array with hashed data will be returned. If some error occurs, null will be returned |
Correct hashing result:
Result with some error
crypt.hmac.sha256(data, key)
Create a hash from provided string using sha256.
Kind: global function
Returns: Object
| Param | Type | Description |
|---|---|---|
| data | string |
Data to be hashed |
| key | Uint8Array |
key to be used for hashing |
crypt.hmac.sha512(data, key)
Create a hash from provided string using sha512.
Kind: global function
Returns: Object
| Param | Type | Description |
|---|---|---|
| data | string |
Data to be hashed |
| key | Uint8Array |
key to be used for hashing |