Search in sources :

Example 1 with PrivateKeyException

use of com.radixdlt.crypto.exception.PrivateKeyException in project radixdlt by radixdlt.

the class BouncyCastleKeyHandler method computePublicKey.

@Override
public byte[] computePublicKey(byte[] privateKey) throws PrivateKeyException, PublicKeyException {
    ECKeyUtils.validatePrivate(privateKey);
    var d = new BigInteger(1, privateKey);
    try {
        var publicKeySpec = new ECPublicKeySpec(spec.getG().multiply(d), spec);
        // and are casting to a bouncy castle ECPublicKey.
        return ((ECPublicKey) KeyFactory.getInstance("EC", "BC").generatePublic(publicKeySpec)).getQ().getEncoded(true);
    } catch (Exception e) {
        throw new PublicKeyException(e);
    }
}
Also used : BigInteger(java.math.BigInteger) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException) ECPublicKeySpec(org.bouncycastle.jce.spec.ECPublicKeySpec) PrivateKeyException(com.radixdlt.crypto.exception.PrivateKeyException) PublicKeyException(com.radixdlt.crypto.exception.PublicKeyException)

Aggregations

PrivateKeyException (com.radixdlt.crypto.exception.PrivateKeyException)1 PublicKeyException (com.radixdlt.crypto.exception.PublicKeyException)1 BigInteger (java.math.BigInteger)1 ECPublicKeySpec (org.bouncycastle.jce.spec.ECPublicKeySpec)1