public final class CryptoUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
AES_KEY_SIZE_IN_BYTES |
static String |
AUTH_SCHEME_DUAL |
static String |
HEADER_AUTHORIZATION |
static String |
HEADER_NONCE |
static String |
HEADER_TIMESTAMP |
static int |
NONCE_SIZE_IN_BYTES |
| Modifier and Type | Method and Description |
|---|---|
String |
computeSHA256(String hex)
Computes a SHA 256 hash of the given hex.
|
String |
decrypt(String cipherText,
byte[] key)
Decrypts ciphertext previously encoded with
encrypt. |
String |
encrypt(String plainText,
byte[] key)
Encrypts the given plain text using the given key using AES with PKCS#5 padding.
|
Map<String,String> |
generateApiHeaders(String apiKey,
String bearerToken,
String signingKey)
Generates the big three API request headers based on the input credentials.
|
String |
generateTimestamp()
Generates a timestamp encoded for use in Gateway API request headers.
|
static CryptoUtils |
getInstance()
Returns the CryptoUtils singleton.
|
byte[] |
randomBytes(int len)
Returns an array of random bytes of the given length.
|
public static final String HEADER_NONCE
public static final String HEADER_TIMESTAMP
public static final String HEADER_AUTHORIZATION
public static final String AUTH_SCHEME_DUAL
public static final int AES_KEY_SIZE_IN_BYTES
public static final int NONCE_SIZE_IN_BYTES
public static CryptoUtils getInstance()
CryptoUtilspublic String computeSHA256(String hex)
hex - data to be hashed in hex format.public Map<String,String> generateApiHeaders(String apiKey, String bearerToken, String signingKey)
apiKey - BlockChyp API Key (root or transient)bearerToken - BlockChyp Bearer Token (root or transient)signingKey - BlockChyp Signing Key (root or transient)Map containing the API request headers.public String generateTimestamp()
public String decrypt(String cipherText, byte[] key) throws Exception
encrypt.cipherText - the initialization vector and ciphertext separated by a pipe character.key - the AES encryption to use.Exception - if the decryption or associated encoding operations fail.public String encrypt(String plainText, byte[] key) throws Exception
plainText - the message to be encryptedkey - AES encryption keyException - if an error occurs during encryption or encoding.public byte[] randomBytes(int len)
len - Number of random bytes to return.Copyright © 2022 BlockChyp, Inc.. All rights reserved.