Ejemplo de tokenización con el módulo SVault mediante generación de token y recuperación de secreto.
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.");
String strMK = "aes256";
api.createKey(strMK, TacNDJavaLib.ALG_AES_256, false);
String strCPF = "26122200468";
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);
String mask = "***\0\0\0***";
String maskedSecret = api.GetSVaultSecret(strMK,
mask,
svaultResponse.getTokenBlob());
System.out.println("Masked secret: " + maskedSecret);
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);
mask = "*******\0\0\0";
maskedSecret = api.GetSVaultSecret(strMK,
mask,
svaultResponse.getTokenBlob());
System.out.println("Masked secret: " + maskedSecret);
api.deleteKey(strMK);
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finalizado.");
}
}