Search in sources :

Example 1 with ECPublicKey

use of org.gudy.bouncycastle.jce.interfaces.ECPublicKey in project BiglyBT by BiglySoftware.

the class JCEECDHKeyAgreement method engineDoPhase.

@Override
protected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException {
    if (privKey == null) {
        throw new IllegalStateException("EC Diffie-Hellman not initialised.");
    }
    if (!lastPhase) {
        throw new IllegalStateException("EC Diffie-Hellman can only be between two parties.");
    }
    if (!(key instanceof ECPublicKey)) {
        throw new InvalidKeyException("EC Key Agreement doPhase requires ECPublicKey");
    }
    CipherParameters pubKey = ECUtil.generatePublicKeyParameter((PublicKey) key);
    result = agreement.calculateAgreement(pubKey);
    return null;
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) ECPublicKey(org.gudy.bouncycastle.jce.interfaces.ECPublicKey)

Example 2 with ECPublicKey

use of org.gudy.bouncycastle.jce.interfaces.ECPublicKey in project BiglyBT by BiglySoftware.

the class ECUtil method generatePublicKeyParameter.

public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey key) throws InvalidKeyException {
    if (key instanceof ECPublicKey) {
        ECPublicKey k = (ECPublicKey) key;
        ECParameterSpec s = k.getParams();
        return new ECPublicKeyParameters(k.getQ(), new ECDomainParameters(s.getCurve(), s.getG(), s.getN()));
    }
    throw new InvalidKeyException("can't identify EC public key.");
}
Also used : ECPublicKey(org.gudy.bouncycastle.jce.interfaces.ECPublicKey) ECDomainParameters(org.gudy.bouncycastle.crypto.params.ECDomainParameters) ECParameterSpec(org.gudy.bouncycastle.jce.spec.ECParameterSpec) InvalidKeyException(java.security.InvalidKeyException) ECPublicKeyParameters(org.gudy.bouncycastle.crypto.params.ECPublicKeyParameters)

Aggregations

ECPublicKey (org.gudy.bouncycastle.jce.interfaces.ECPublicKey)2 InvalidKeyException (java.security.InvalidKeyException)1 CipherParameters (org.gudy.bouncycastle.crypto.CipherParameters)1 ECDomainParameters (org.gudy.bouncycastle.crypto.params.ECDomainParameters)1 ECPublicKeyParameters (org.gudy.bouncycastle.crypto.params.ECPublicKeyParameters)1 ECParameterSpec (org.gudy.bouncycastle.jce.spec.ECParameterSpec)1