GenerateMAC.java

Exemplo de geração de MAC.

Veja Nota sobre os exemplos.
package doxy.examples;
public class GenerateMAC {
private static String strAddr = "10.0.62.16";
private static String strUsrId = "master";
private static String strPwd = "12345678";
private static String hmacKeyName = "hmac_key";
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
System.out.println("--> Login HSM");
api.openSession(strAddr, strUsrId, strPwd);
System.out.println("--> Create a HMAC key");
api.createKey(hmacKeyName, TacNDJavaLib.ALG_HMAC_SHA2_256, true);
byte message1[] =
{
(byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x37, (byte)0x38,
(byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x37, (byte)0x38
} ;
byte message2[] =
{
(byte)0x31, (byte)0x31, (byte)0x31, (byte)0x31, (byte)0x31, (byte)0x31, (byte)0x31, (byte)0x31,
(byte)0x32, (byte)0x32, (byte)0x32, (byte)0x32, (byte)0x32, (byte)0x32, (byte)0x32, (byte)0x32,
} ;
System.out.println("--> Generate HMAC in one operation");
byte[] mac = api.generateMAC(TacNDJavaLib.ALG_HMAC_SHA2_256,
hmacKeyName,
message1);
System.out.println("--> Initialize a HMAC multiple parts operation");
api.initMAC(TacNDJavaLib.ALG_HMAC_SHA2_256,
hmacKeyName);
System.out.println("--> Update part 1");
api.updateMAC(message1);
System.out.println("--> Update part 2");
api.updateMAC(message2);
System.out.println("--> End multiple parts MAC operation");
mac = api.endMAC();
api.closeSession();
System.out.println("The process ended sucessfully");
}
}