API Java
HSM Dinamo
Cargando...
Buscando...
No se han encontrado entradas
SignVerifyHashedData.java

Ejemplo de firma y verificación mediante hashes de datos previamente calculados.

Véase la nota sobre ejemplos.
package doxy.examples;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class SignVerifyHashedData {
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
api.openSession("127.0.0.1", "master", "12345678", false);
String message = "teste teste teste";
byte bHash[] =
{
(byte)0x8F, (byte)0xB2, (byte)0x76, (byte)0x64, (byte)0x9F, (byte)0x23, (byte)0xCE, (byte)0xCF, (byte)0x02, (byte)0x8B, (byte)0xA1, (byte)0xEF, (byte)0xF4, (byte)0x25, (byte)0x38, (byte)0xE3,
(byte)0x0A, (byte)0x0C, (byte)0x56, (byte)0x0F, (byte)0xE5, (byte)0x66, (byte)0x82, (byte)0x8E, (byte)0xBB, (byte)0xA5, (byte)0x7C, (byte)0x56, (byte)0x8E, (byte)0x79, (byte)0x33, (byte)0x54,
} ;
String keyId = "rsa";
api.createKey(keyId, TacNDJavaLib.ALG_RSA_2048);
//Assina utilizando o nome da chave
byte[] signature = api.signHashedData(keyId, TacNDJavaLib.ALG_SHA2_256, bHash);
api.verifySignature(keyId, TacNDJavaLib.ALG_SHA2_256, signature, message.getBytes());
//Assina utilizando key handle
byte[] privateKeyHandle = api.getUserKey(keyId);
signature = api.signHashedData(privateKeyHandle, TacNDJavaLib.ALG_SHA2_256, bHash, 0);
api.releaseKeyHandle(privateKeyHandle);
api.verifySignature(keyId, TacNDJavaLib.ALG_SHA2_256, signature, message.getBytes());
api.deleteKey(keyId);
api.closeSession();
}
}