Ejemplo de importación y exportación de una clave en formato PKCS#12 (PFX).
package doxy.examples;
import java.io.FileOutputStream;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class ImportExportP12 {
static String ip = "127.0.0.1";
static String user = "master";
static String password = "12345678";
public static void main(String[] args) throws TacException {
Dinamo api = new Dinamo();
api.openSession(ip, user, password);
String priKeyName = "lab";
String certName = "lab_cert";
api.importPKCS12("./c12345678.pfx",
"12345678",
priKeyName,
certName,
true);
String pkcs12Password = "12345678";
byte[] pkcs12Buffer = api.exportPKCS12(pkcs12Password,
priKeyName,
certName);
try {
FileOutputStream stream = new FileOutputStream("./c12345678_exp.pfx");
stream.write(pkcs12Buffer);
stream.close();
} catch(Exception e)
{
e.printStackTrace();
}
String priImpKeyName = "lab2";
String certImpName = "lab2_cert";
api.importPKCS12(pkcs12Buffer,
pkcs12Password,
priImpKeyName,
certImpName,
true);
api.closeSession();
}
}