java.lang.Object
com.hedera.hashgraph.sdk.Crypto
Utility class used internally by the sdk.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int(package private) static final int(package private) static final org.bouncycastle.asn1.x9.X9ECParameters(package private) static final org.bouncycastle.crypto.params.ECDomainParameters(package private) static final int(package private) static final int(package private) static final int -
Method Summary
Modifier and TypeMethodDescription(package private) static byte[]calcHmacSha384(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv, byte[] input) Calculate a hash message authentication code using the secure hash algorithm variant 384.(package private) static byte[]calcKeccak256(byte[] message) Calculate a keccak 256-bit hash.(package private) static byte[]decryptAesCtr128(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv, byte[] input) Decrypt a byte array with the aes ctr cipher.(package private) static org.bouncycastle.crypto.params.KeyParameterderiveKeySha256(String passphrase, byte[] salt, int iterations, int dkLenBytes) Derive a sha 256 key.(package private) static byte[]encryptAesCtr128(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv, byte[] input) Encrypt a byte array with the aes ctr cipher.(package private) static CipherinitAesCbc128Decrypt(org.bouncycastle.crypto.params.KeyParameter cipherKey, AlgorithmParameters parameters) Initialize an advanced encryption standard cipher block chaining mode cipher for decryption.(package private) static CipherinitAesCbc128Encrypt(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv) Initialize an advanced encryption standard cipher block chaining mode cipher for encryption.(package private) static CipherinitAesCtr128(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv, boolean forDecrypt) Initialize an advanced encryption standard counter mode cipher.(package private) static byte[]randomBytes(int len) Generate some randomness.(package private) static byte[]recoverPublicKeyECDSAFromSignature(int recId, BigInteger r, BigInteger s, byte[] messageHash) Given the r and s components of a signature and the hash value of the message, recover and return the public key according to the algorithm in SEC1v2 section 4.1.6.(package private) static byte[]Run the cipher on the given input.
-
Field Details
-
IV_LEN
static final int IV_LEN- See Also:
-
ITERATIONS
static final int ITERATIONS- See Also:
-
SALT_LEN
static final int SALT_LEN- See Also:
-
DK_LEN
static final int DK_LEN- See Also:
-
CBC_DK_LEN
static final int CBC_DK_LEN- See Also:
-
ECDSA_SECP256K1_CURVE
static final org.bouncycastle.asn1.x9.X9ECParameters ECDSA_SECP256K1_CURVE -
ECDSA_SECP256K1_DOMAIN
static final org.bouncycastle.crypto.params.ECDomainParameters ECDSA_SECP256K1_DOMAIN
-
-
Method Details
-
deriveKeySha256
static org.bouncycastle.crypto.params.KeyParameter deriveKeySha256(String passphrase, byte[] salt, int iterations, int dkLenBytes) Derive a sha 256 key.- Parameters:
passphrase- the password will be converted into bytessalt- the salt to be mixed initerations- the iterations for mixingdkLenBytes- the key length in bytes- Returns:
- the key parameter object
-
initAesCtr128
static Cipher initAesCtr128(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv, boolean forDecrypt) Initialize an advanced encryption standard counter mode cipher.- Parameters:
cipherKey- the cipher keyiv- the initialization vector byte arrayforDecrypt- is this for decryption- Returns:
- the aes ctr cipher
-
initAesCbc128Encrypt
static Cipher initAesCbc128Encrypt(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv) Initialize an advanced encryption standard cipher block chaining mode cipher for encryption.- Parameters:
cipherKey- the cipher keyiv- the initialization vector byte array- Returns:
- the aes cbc cipher
-
initAesCbc128Decrypt
static Cipher initAesCbc128Decrypt(org.bouncycastle.crypto.params.KeyParameter cipherKey, AlgorithmParameters parameters) Initialize an advanced encryption standard cipher block chaining mode cipher for decryption.- Parameters:
cipherKey- the cipher keyparameters- the algorithm parameters- Returns:
- the aes cbc cipher
-
encryptAesCtr128
static byte[] encryptAesCtr128(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv, byte[] input) Encrypt a byte array with the aes ctr cipher.- Parameters:
cipherKey- the cipher keyiv- the initialization vectorinput- the byte array to encrypt- Returns:
- the encrypted byte array
-
decryptAesCtr128
static byte[] decryptAesCtr128(org.bouncycastle.crypto.params.KeyParameter cipherKey, byte[] iv, byte[] input) Decrypt a byte array with the aes ctr cipher.- Parameters:
cipherKey- the cipher keyiv- the initialization vectorinput- the byte array to decrypt- Returns:
- the decrypted byte array
-
runCipher
Run the cipher on the given input.- Parameters:
cipher- the cipherinput- the byte array- Returns:
- the output of running the cipher
-
calcHmacSha384
static byte[] calcHmacSha384(org.bouncycastle.crypto.params.KeyParameter cipherKey, @Nullable byte[] iv, byte[] input) Calculate a hash message authentication code using the secure hash algorithm variant 384.- Parameters:
cipherKey- the cipher keyiv- the initialization vectorinput- the byte array- Returns:
- the hmac using sha 384
-
calcKeccak256
static byte[] calcKeccak256(byte[] message) Calculate a keccak 256-bit hash.- Parameters:
message- the message to be hashed- Returns:
- the hash
-
randomBytes
static byte[] randomBytes(int len) Generate some randomness.- Parameters:
len- the number of bytes requested- Returns:
- the byte array of randomness
-
recoverPublicKeyECDSAFromSignature
static byte[] recoverPublicKeyECDSAFromSignature(int recId, BigInteger r, BigInteger s, byte[] messageHash) Given the r and s components of a signature and the hash value of the message, recover and return the public key according to the algorithm in SEC1v2 section 4.1.6.Calculations and explanations in this method were taken and adapted from incubator-tuweni lib
- Parameters:
recId- Which possible key to recover.r- The R component of the signature.s- The S component of the signature.messageHash- Hash of the data that was signed.- Returns:
- A ECKey containing only the public part, or
nullif recovery wasn't possible.
-