Example of HMAC Computing
Contents
- Introduction to the Library
- Basic support package (com.kryptel.bslx)
- Kryptel API Commons package (com.kryptel)
- Cipher package (com.kryptel.cipher)
- Compressor package (com.kryptel.compressor)
- Exceptions package (com.kryptel.exceptions)
- Hash function package (com.kryptel.hash_function)
- MAC function package (com.kryptel.mac)
- IMacSetup interface
- Example: Computing string HMAC
- Key-related functions (com.kryptel.key)
- Silver Key engine (com.kryptel.silver_key)
- Kryptel encrypted storage (com.kryptel.storage)
Computing String HMAC
This function accepts a string, a password, a hash function Component ID, and returns the string's HMAC. The provided hash function is used for both HMAC computing and password conversion.
public static byte[] ComputeStringHmac(String str, String password, UUID cidHashFunc) throws Exception { IKryptelComponent hmacComp = Loader.CreateComponent(CID_HMAC); IMacSetup hmacSetup = (IMacSetup)hmacComp.GetInterface(IID_IMacSetup); hmacSetup.SetBase(cidHashFunc); KeyRecord kr = ApiHelpers.PasswordToKeyRecord(password, cidHashFunc); hmacSetup.SetKey(kr.keyData, 0, kr.keyData.length); IMemoryBlockHash hmacMem = (IMemoryBlockHash)hmacComp.GetInterface(IID_IMemoryBlockHash); return hmacMem.HashWideString(str); }
Interfaces used: IMacSetup, IMemoryBlockHash.
More about components: Components, Loader class, IKryptelComponent interface.
See Also: ApiHelpers class, KeyRecord structure.