Java API
HSM Dinamo
Todos Estruturas de dados Namespaces Arquivos Funções Variáveis Grupos Páginas
Tokenization.java

Example of tokenization with the SVault module using token generation and secret recovery.

See Note on examples.
package doxy.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.dinamonetworks.Dinamo;
import com.dinamonetworks.SVaultGenTokenResponse;
import br.com.trueaccess.TacNDJavaLib;
public class Tokenization {
public static void main(String[] args) throws IOException {
String strAddr = "127.0.0.1";
String strUsrId = "master";
String strPwd = "12345678";
int nPort = 4433;
int nFlags = 0;
Dinamo api = new Dinamo();
try {
api.openSession(strAddr, strUsrId, strPwd, nPort, nFlags);
System.out.println("Conectado.");
/*
*
* Teste de Dígito.
*
* */
String strMK = "aes256"; //Nome da chave no HSM
/*
* Cria chave mestra para tokenização.
*/
api.createKey(strMK, TacNDJavaLib.ALG_AES_256, false);
String strCPF = "26122200468"; //CPF para ser tokenizado
SVaultGenTokenResponse svaultResponse = api.GenSVaultDigitToken(TacNDJavaLib.D_SVAULT_CKS_CPF,
TacNDJavaLib.D_SVAULT_F_MASK_SECRET,
strMK,
strCPF);
System.out.println("Token: " + svaultResponse.getToken());
String token = api.GetSVaultToken(strMK, "", svaultResponse.getTokenBlob());
System.out.println("Token: " + token);
String secret = api.GetSVaultSecret(strMK,
"",
svaultResponse.getTokenBlob());
System.out.println("Secret: " + secret);
/*
* Aplica máscara que encobre com o caracter "*" os 3 primeiros e os 3 últimos dígitos do CPF.
* */
String mask = "***\0\0\0***";
String maskedSecret = api.GetSVaultSecret(strMK,
mask,
svaultResponse.getTokenBlob());
System.out.println("Masked secret: " + maskedSecret);
/*
*
* Teste de String.
*
* */
String strText = "Este é um teste";
svaultResponse = api.GenSVaultStringToken(TacNDJavaLib.D_SVAULT_F_MASK_SECRET,
strMK,
strText);
System.out.println("Token: " + svaultResponse.getToken());
token = api.GetSVaultToken(strMK, "", svaultResponse.getTokenBlob());
System.out.println("Token: " + token);
secret = api.GetSVaultSecret(strMK,
"",
svaultResponse.getTokenBlob());
System.out.println("Secret: " + secret);
/*
* Aplica máscara sobre a string.
* */
mask = "*******\0\0\0";
maskedSecret = api.GetSVaultSecret(strMK,
mask,
svaultResponse.getTokenBlob());
System.out.println("Masked secret: " + maskedSecret);
/*
* Remove a chave mestra de testes.
* */
api.deleteKey(strMK);
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finalizado.");
}
}