use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2PrivateKey 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.SM2PrivateKey in project web3sdk by FISCO-BCOS.
the class SM2KeyGenerator method generatePrivateKey.
/*
* 根据数据生成SM2私钥
*
* @param imei 手机序列号
*
* @param pin pin码
*
* @param rand 随机数
*
* @return String 私钥(16进制字符串,256bits)
*/
private SM2PrivateKey generatePrivateKey() {
SecureRandom random = new SecureRandom();
byte[] r = new byte[32];
BigInteger k;
do {
random.nextBytes(r);
k = new BigInteger(1, r);
} while (!checkValidateK(k));
byte[] in = k.toByteArray();
SM3Digest digest = new SM3Digest();
byte[] out = new byte[32];
digest.update(in, 0, in.length);
digest.doFinal(out, 0);
String value = KeyUtils.bcdhex_to_aschex(out);
return new SM2PrivateKey(new BigInteger(value, 16));
}
Aggregations