use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2PublicKey in project web3sdk by FISCO-BCOS.
the class GenCredential method genEcPairFromKeyPair.
private static ECKeyPair genEcPairFromKeyPair(KeyPair keyPairData) {
try {
SM2PrivateKey vk = (SM2PrivateKey) keyPairData.getPrivate();
SM2PublicKey pk = (SM2PublicKey) keyPairData.getPublic();
final byte[] publicKey = pk.getEncoded();
final byte[] privateKey = vk.getEncoded();
BigInteger biPublic = new BigInteger(Hex.toHexString(publicKey), 16);
BigInteger biPrivate = new BigInteger(Hex.toHexString(privateKey), 16);
ECKeyPair keyPair = new ECKeyPair(biPrivate, biPublic);
return keyPair;
} catch (Exception e) {
logger.error("create ec_keypair of guomi failed, error msg:" + e.getMessage());
return null;
}
}
use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2PublicKey in project web3sdk by FISCO-BCOS.
the class Sign method smPublicKeyFromPrivate.
/**
* Returns sm public key from the given private key.
*
* @param biPrivateKey the private key to derive the public key from
* @return BigInteger encoded public key
*/
public static BigInteger smPublicKeyFromPrivate(BigInteger biPrivateKey) {
String privateKey = biPrivateKey.toString(16);
SM2KeyGenerator generator = new SM2KeyGenerator();
final KeyPair keyPairData = generator.generateKeyPair(privateKey);
SM2PublicKey pk = (SM2PublicKey) keyPairData.getPublic();
final byte[] publicKey = pk.getEncoded();
BigInteger biPublicKey = new BigInteger(Hex.toHexString(publicKey), 16);
return biPublicKey;
}
Aggregations