Java API
HSM Dinamo
Loading...
Looking for...
No entries found
BchainCreateXPrvGetPubKey.java

Example of generating an XPrv BIP32 key and retrieving the public key using the blockchain module.

See Note on examples.
package doxy.examples;
import com.dinamonetworks.Dinamo;
import br.com.trueaccess.TacException;
import br.com.trueaccess.TacNDJavaLib;
public class BchainCreateXPrvGetPubKey {
public static void main(String[] args) throws TacException {
String ip = "127.0.0.1";
String user = "master";
String password = "12345678";
Dinamo api = new Dinamo();
api.openSession(ip, user, password);
String xprvId = "xprv_pubkey_example";
// Cria uma chave XPrv BIP32 (mainnet)
api.bchainCreateXPrv(TacNDJavaLib.DN_BCHAIN_BIP32_XPRV,
TacNDJavaLib.DN_BCHAIN_VER_BIP32_MAINNET,
0,
xprvId);
System.out.println("Chave XPrv criada: " + xprvId);
// Recupera a chave pública correspondente no formato SEC1 comprimido
byte[] pubKey = api.bchainGetPubKey(TacNDJavaLib.DN_BCHAIN_PBK_SEC1_COMP, xprvId);
System.out.println("Chave pública recuperada (" + pubKey.length + " bytes).");
// Remove a chave criada
api.deleteKeyIfExists(xprvId);
System.out.println("Chave XPrv removida: " + xprvId);
api.closeSession();
}
}