Class HashBasedCounterUtils
java.lang.Object
io.getlime.security.powerauth.crypto.lib.util.HashBasedCounterUtils
The
HashBasedCounterUtils class provides additional functionality that allows secure transfer
and verification of hash based counter over the network.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]calculateHashFromHashBasedCounter(byte[] ctrData, SecretKey transportKey) Calculate hash from value representing the hash based counter.booleanverifyHashForHashBasedCounter(byte[] receivedCtrDataHash, byte[] expectedCtrData, SecretKey transportKey) Verify whether client's value of hash based counter is equal to the value received from the server.
-
Constructor Details
-
HashBasedCounterUtils
public HashBasedCounterUtils()
-
-
Method Details
-
calculateHashFromHashBasedCounter
public byte[] calculateHashFromHashBasedCounter(byte[] ctrData, SecretKey transportKey) throws CryptoProviderException, InvalidKeyException, GenericCryptoException Calculate hash from value representing the hash based counter. HMAC-SHA256 is currently used as a hashing function.- Parameters:
ctrData- Hash-based counter.transportKey- Transport key.- Returns:
- Hash calculated from provided hash-based counter.
- Throws:
GenericCryptoException- In case that key derivation fails or you provided invalid ctrData.CryptoProviderException- In case cryptography provider is incorrectly initialized.InvalidKeyException- In case that transport key is not valid.
-
verifyHashForHashBasedCounter
public boolean verifyHashForHashBasedCounter(byte[] receivedCtrDataHash, byte[] expectedCtrData, SecretKey transportKey) throws CryptoProviderException, InvalidKeyException, GenericCryptoException Verify whether client's value of hash based counter is equal to the value received from the server. The value received from the server is already hashed, so the function has to calculate hash from the client's counter and then compare both values.- Parameters:
receivedCtrDataHash- Value received from the server, containing hash, calculated from hash based counter.expectedCtrData- Expected hash based counter.transportKey- Transport key.- Returns:
truein case that received hash equals to hash calculated from counter data.- Throws:
InvalidKeyException- When invalid key is provided.GenericCryptoException- In case key derivation fails.CryptoProviderException- In case cryptography provider is incorrectly initialized.
-