Search in sources :

Example 1 with SM2KeyGenerator

use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator 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;
}
Also used : KeyPair(java.security.KeyPair) SM2PublicKey(org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2PublicKey) SM2KeyGenerator(org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator) BigInteger(java.math.BigInteger)

Example 2 with SM2KeyGenerator

use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator in project web3sdk by FISCO-BCOS.

the class GenCredential method createGuomiKeyPair.

public static ECKeyPair createGuomiKeyPair() {
    final SM2KeyGenerator generator = new SM2KeyGenerator();
    final KeyPair keyPairData = generator.generateKeyPair();
    if (keyPairData != null)
        return genEcPairFromKeyPair(keyPairData);
    return null;
}
Also used : KeyPair(java.security.KeyPair) ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) SM2KeyGenerator(org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator)

Example 3 with SM2KeyGenerator

use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator in project web3sdk by FISCO-BCOS.

the class GenCredential method createGuomiKeyPair.

public static ECKeyPair createGuomiKeyPair(String privKey) {
    SM2KeyGenerator generator = new SM2KeyGenerator();
    final KeyPair keyPairData = generator.generateKeyPair(privKey);
    if (keyPairData != null)
        return genEcPairFromKeyPair(keyPairData);
    return null;
}
Also used : KeyPair(java.security.KeyPair) ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) SM2KeyGenerator(org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator)

Aggregations

KeyPair (java.security.KeyPair)3 SM2KeyGenerator (org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator)3 ECKeyPair (org.fisco.bcos.web3j.crypto.ECKeyPair)2 BigInteger (java.math.BigInteger)1 SM2PublicKey (org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2PublicKey)1