Package com.blockchyp.client.crypto
Class CryptoUtils
java.lang.Object
com.blockchyp.client.crypto.CryptoUtils
This is utility class providing cryptography support for the BlockChyp client.
It handles the authorization headers required for direct gateway requests along
with AES encryption for the offline route cache.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncomputeSHA256(String hex) Computes a SHA 256 hash of the given hex.Decrypts ciphertext previously encoded withencrypt(java.lang.String,byte[]).Encrypts the given plain text using the given key using AES with PKCS#5 padding.generateApiHeaders(String apiKey, String bearerToken, String signingKey) Generates the big three API request headers based on the input credentials.Generates a timestamp encoded for use in Gateway API request headers.static CryptoUtilsReturns the CryptoUtils singleton.byte[]randomBytes(int len) Returns an array of random bytes of the given length.
-
Field Details
-
HEADER_NONCE
- See Also:
-
HEADER_TIMESTAMP
- See Also:
-
HEADER_AUTHORIZATION
- See Also:
-
AUTH_SCHEME_DUAL
- See Also:
-
AES_KEY_SIZE_IN_BYTES
public static final int AES_KEY_SIZE_IN_BYTES- See Also:
-
NONCE_SIZE_IN_BYTES
public static final int NONCE_SIZE_IN_BYTES- See Also:
-
-
Method Details
-
getInstance
Returns the CryptoUtils singleton.- Returns:
- an instance of
CryptoUtils
-
computeSHA256
Computes a SHA 256 hash of the given hex.- Parameters:
hex- data to be hashed in hex format.- Returns:
- hex encoded hash of the input data
-
generateApiHeaders
Generates the big three API request headers based on the input credentials.- Parameters:
apiKey- BlockChyp API Key (root or transient)bearerToken- BlockChyp Bearer Token (root or transient)signingKey- BlockChyp Signing Key (root or transient)- Returns:
- a
Mapcontaining the API request headers.
-
generateTimestamp
Generates a timestamp encoded for use in Gateway API request headers.- Returns:
- ISO encoded UTC timestamp string.
-
decrypt
Decrypts ciphertext previously encoded withencrypt(java.lang.String,byte[]).- Parameters:
cipherText- the initialization vector and ciphertext separated by a pipe character.key- the AES encryption to use.- Returns:
- the plain text
- Throws:
Exception- if the decryption or associated encoding operations fail.
-
encrypt
Encrypts the given plain text using the given key using AES with PKCS#5 padding. Generates and returns a CBC initialization vector prepended to the main ciphertext.- Parameters:
plainText- the message to be encryptedkey- AES encryption key- Returns:
- return hex encoded initialization vector and ciphertext, pipe delimited.
- Throws:
Exception- if an error occurs during encryption or encoding.
-
randomBytes
public byte[] randomBytes(int len) Returns an array of random bytes of the given length.- Parameters:
len- Number of random bytes to return.- Returns:
- byte[]
-