波场的签名算法是ECDSA,选用的曲线是SECP256K1。
从0.1.3版本开始,trident-java在Core中实现了一个对于SECP256K1.KeyPair的包装类,方便私钥的生成,以及私钥到地址的转换。这个类路径为:org.tron.trident.core.key.KeyPair;
- 生成秘钥对
KeyPair keyPair = KeyPair.generate();
- 用私钥导入秘钥对
KeyPair keyPair = new KeyPair("your private key");
- 查看私钥&公钥
keyPair.toPrivateKey(); //String private key
keyPair.toPublicKey(); //String public key
注意
公钥不是地址。
- 查看Base58Check & Hex格式地址
keyPair.toBase58CheckAddress();
keyPair.toHexAddress();
- 用特定的公钥转换为byte[],Base58Check或Hex地址
//the parent function, returns byte[]
KeyPair.publicKeyToAddress(SECP256K1.PublicKey pubKey);
KeyPair.publicKeyToBase58CheckAddress(SECP256K1.PublicKey pubKey);
KeyPair.publicKeyToHexAddress(SECP256K1.PublicKey pubKey);
- 签名
//this function returns the signature message in byte[]
KeyPair.signTransaction(byte[] txid, KeyPair keyPair);