Search in sources :

Example 1 with SecP256K1Curve

use of org.bouncycastle.math.ec.custom.sec.SecP256K1Curve in project web3sdk by FISCO-BCOS.

the class ECCEncrypt method createBCECPublicKey.

/**
 * create BCECPublicKey from publicKey and privateKey
 *
 * @param publicKey
 * @return
 */
private BCECPublicKey createBCECPublicKey(BigInteger publicKey) {
    // Handle public key.
    String publicKeyValue = Numeric.toHexStringNoPrefixZeroPadded(publicKey, Keys.PUBLIC_KEY_LENGTH_IN_HEX);
    String prePublicKeyStr = publicKeyValue.substring(0, 64);
    String postPublicKeyStr = publicKeyValue.substring(64);
    SecP256K1Curve secP256K1Curve = new SecP256K1Curve();
    SecP256K1Point secP256K1Point = (SecP256K1Point) secP256K1Curve.createPoint(new BigInteger(prePublicKeyStr, 16), new BigInteger(postPublicKeyStr, 16));
    SecP256K1Point secP256K1PointG = (SecP256K1Point) secP256K1Curve.createPoint(ECCParams.POINTG_PRE, ECCParams.POINTG_POST);
    ECDomainParameters domainParameters = new ECDomainParameters(secP256K1Curve, secP256K1PointG, ECCParams.FACTOR_N);
    ECPublicKeyParameters publicKeyParameters = new ECPublicKeyParameters(secP256K1Point, domainParameters);
    BCECPublicKey bcecPublicKey = new BCECPublicKey("ECDSA", publicKeyParameters, ECCParams.ecNamedCurveSpec, BouncyCastleProvider.CONFIGURATION);
    return bcecPublicKey;
}
Also used : ECDomainParameters(org.bouncycastle.crypto.params.ECDomainParameters) SecP256K1Point(org.bouncycastle.math.ec.custom.sec.SecP256K1Point) BCECPublicKey(org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey) BigInteger(java.math.BigInteger) SecP256K1Curve(org.bouncycastle.math.ec.custom.sec.SecP256K1Curve) ECPublicKeyParameters(org.bouncycastle.crypto.params.ECPublicKeyParameters)

Aggregations

BigInteger (java.math.BigInteger)1 ECDomainParameters (org.bouncycastle.crypto.params.ECDomainParameters)1 ECPublicKeyParameters (org.bouncycastle.crypto.params.ECPublicKeyParameters)1 BCECPublicKey (org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey)1 SecP256K1Curve (org.bouncycastle.math.ec.custom.sec.SecP256K1Curve)1 SecP256K1Point (org.bouncycastle.math.ec.custom.sec.SecP256K1Point)1