Search in sources :

Example 1 with ECKey

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

the class JDKDSASigner method engineInitVerify.

@Override
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    CipherParameters param = null;
    if (publicKey instanceof ECKey) {
        param = ECUtil.generatePublicKeyParameter(publicKey);
    } else if (publicKey instanceof DSAKey) {
        param = DSAUtil.generatePublicKeyParameter(publicKey);
    } else {
        try {
            /*
                byte[]  bytes = publicKey.getEncoded();

                publicKey = JDKKeyFactory.createPublicKeyFromDERStream(
                                        new ByteArrayInputStream(bytes));

                if (publicKey instanceof ECKey)
                {
                    param = ECUtil.generatePublicKeyParameter(publicKey);
                }
                else if (publicKey instanceof DSAKey)
                {
                    param = DSAUtil.generatePublicKeyParameter(publicKey);
                }
                else
                {
                */
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        // }
        } catch (Exception e) {
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        }
    }
    digest.reset();
    signer.init(false, param);
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) DSAKey(java.security.interfaces.DSAKey) ECKey(org.gudy.bouncycastle.jce.interfaces.ECKey) IOException(java.io.IOException)

Example 2 with ECKey

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

the class JDKDSASigner method engineInitSign.

@Override
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
    CipherParameters param = null;
    if (privateKey instanceof ECKey) {
        param = ECUtil.generatePrivateKeyParameter(privateKey);
    } else {
        param = DSAUtil.generatePrivateKeyParameter(privateKey);
    }
    digest.reset();
    if (random != null) {
        signer.init(true, new ParametersWithRandom(param, random));
    } else {
        signer.init(true, param);
    }
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) ParametersWithRandom(org.gudy.bouncycastle.crypto.params.ParametersWithRandom) ECKey(org.gudy.bouncycastle.jce.interfaces.ECKey)

Aggregations

CipherParameters (org.gudy.bouncycastle.crypto.CipherParameters)2 ECKey (org.gudy.bouncycastle.jce.interfaces.ECKey)2 IOException (java.io.IOException)1 DSAKey (java.security.interfaces.DSAKey)1 ParametersWithRandom (org.gudy.bouncycastle.crypto.params.ParametersWithRandom)1