Exemplo de geração de hash.
package doxy.examples;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class GenerateHash {
private static String strAddr = "127.0.0.1";
private static String strUsrId = "master";
private static String strPwd = "12345678";
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
System.out.println("--> Login HSM");
api.openSession(strAddr, strUsrId, strPwd);
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 HASH in one operation");
byte[] mac = api.generateHash( TacNDJavaLib.ALG_SHA2_256,
message1);
System.out.println("--> Initialize a HASH multiple parts operation");
api.initHash(TacNDJavaLib.ALG_SHA2_256);
System.out.println("--> Update part 1");
api.updateHash(message1);
System.out.println("--> Update part 2");
api.updateHash(message2);
System.out.println("--> End multiple parts HASH operation");
mac = api.endHash();
api.closeSession();
System.out.println("The process ended sucessfully");
}
}