Search in sources :

Example 1 with ECPublicKey

use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.

the class ECGOST2012SignatureSpi256 method engineInitVerify.

protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    ECKeyParameters param;
    if (publicKey instanceof ECPublicKey) {
        param = (ECKeyParameters) generatePublicKeyParameter(publicKey);
    } else {
        try {
            byte[] bytes = publicKey.getEncoded();
            publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
            param = (ECKeyParameters) ECUtil.generatePublicKeyParameter(publicKey);
        } catch (Exception e) {
            throw new InvalidKeyException("cannot recognise key type in ECGOST-2012-256 signer");
        }
    }
    if (param.getParameters().getN().bitLength() > 256) {
        throw new InvalidKeyException("key out of range for ECGOST-2012-256");
    }
    digest.reset();
    signer.init(false, param);
}
Also used : ECKeyParameters(com.github.zhenwei.core.crypto.params.ECKeyParameters) ECPublicKey(com.github.zhenwei.provider.jce.interfaces.ECPublicKey) InvalidKeyException(java.security.InvalidKeyException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 2 with ECPublicKey

use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.

the class SignatureSpi method engineInitVerify.

protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    CipherParameters param;
    if (publicKey instanceof ECPublicKey) {
        param = ECUtil.generatePublicKeyParameter(publicKey);
    } else if (publicKey instanceof GOST3410Key) {
        param = GOST3410Util.generatePublicKeyParameter(publicKey);
    } else {
        try {
            byte[] bytes = publicKey.getEncoded();
            publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
            if (publicKey instanceof ECPublicKey) {
                param = ECUtil.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(com.github.zhenwei.core.crypto.CipherParameters) ECPublicKey(com.github.zhenwei.provider.jce.interfaces.ECPublicKey) GOST3410Key(com.github.zhenwei.provider.jce.interfaces.GOST3410Key) InvalidKeyException(java.security.InvalidKeyException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 3 with ECPublicKey

use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.

the class SignatureSpi method engineInitVerify.

protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    CipherParameters param;
    if (publicKey instanceof ECPublicKey) {
        param = generatePublicKeyParameter(publicKey);
    } else if (publicKey instanceof GOST3410Key) {
        param = GOST3410Util.generatePublicKeyParameter(publicKey);
    } else {
        try {
            byte[] bytes = publicKey.getEncoded();
            publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
            param = ECUtil.generatePublicKeyParameter(publicKey);
        } catch (Exception e) {
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        }
    }
    digest.reset();
    signer.init(false, param);
}
Also used : CipherParameters(com.github.zhenwei.core.crypto.CipherParameters) ECPublicKey(com.github.zhenwei.provider.jce.interfaces.ECPublicKey) GOST3410Key(com.github.zhenwei.provider.jce.interfaces.GOST3410Key) InvalidKeyException(java.security.InvalidKeyException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 4 with ECPublicKey

use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.

the class ECGOST2012SignatureSpi512 method engineInitVerify.

protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    ECKeyParameters param;
    if (publicKey instanceof ECPublicKey) {
        param = (ECKeyParameters) generatePublicKeyParameter(publicKey);
    } else {
        try {
            byte[] bytes = publicKey.getEncoded();
            publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
            param = (ECKeyParameters) ECUtil.generatePublicKeyParameter(publicKey);
        } catch (Exception e) {
            throw new InvalidKeyException("cannot recognise key type in ECGOST-2012-512 signer");
        }
    }
    if (param.getParameters().getN().bitLength() < 505) {
        throw new InvalidKeyException("key too weak for ECGOST-2012-512");
    }
    digest.reset();
    signer.init(false, param);
}
Also used : ECKeyParameters(com.github.zhenwei.core.crypto.params.ECKeyParameters) ECPublicKey(com.github.zhenwei.provider.jce.interfaces.ECPublicKey) InvalidKeyException(java.security.InvalidKeyException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 5 with ECPublicKey

use of com.github.zhenwei.provider.jce.interfaces.ECPublicKey in project LinLong-Java by zhenwei1108.

the class ECUtil method generatePublicKeyParameter.

public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey key) throws InvalidKeyException {
    if (key instanceof ECPublicKey) {
        ECPublicKey k = (ECPublicKey) key;
        ECParameterSpec s = k.getParameters();
        return new ECPublicKeyParameters(k.getQ(), new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
    } else if (key instanceof java.security.interfaces.ECPublicKey) {
        java.security.interfaces.ECPublicKey pubKey = (java.security.interfaces.ECPublicKey) key;
        ECParameterSpec s = EC5Util.convertSpec(pubKey.getParams());
        return new ECPublicKeyParameters(EC5Util.convertPoint(pubKey.getParams(), pubKey.getW()), new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
    } else {
        // see if we can build a key from key.getEncoded()
        try {
            byte[] bytes = key.getEncoded();
            if (bytes == null) {
                throw new InvalidKeyException("no encoding for EC public key");
            }
            PublicKey publicKey = WeGooProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));
            if (publicKey instanceof java.security.interfaces.ECPublicKey) {
                return ECUtil.generatePublicKeyParameter(publicKey);
            }
        } catch (Exception e) {
            throw new InvalidKeyException("cannot identify EC public key: " + e.toString());
        }
    }
    throw new InvalidKeyException("cannot identify EC public key.");
}
Also used : ECPublicKey(com.github.zhenwei.provider.jce.interfaces.ECPublicKey) ECDomainParameters(com.github.zhenwei.core.crypto.params.ECDomainParameters) ECParameterSpec(com.github.zhenwei.provider.jce.spec.ECParameterSpec) PublicKey(java.security.PublicKey) ECPublicKey(com.github.zhenwei.provider.jce.interfaces.ECPublicKey) InvalidKeyException(java.security.InvalidKeyException) ECPublicKeyParameters(com.github.zhenwei.core.crypto.params.ECPublicKeyParameters) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

ECPublicKey (com.github.zhenwei.provider.jce.interfaces.ECPublicKey)5 InvalidKeyException (java.security.InvalidKeyException)5 SignatureException (java.security.SignatureException)4 CipherParameters (com.github.zhenwei.core.crypto.CipherParameters)2 ECKeyParameters (com.github.zhenwei.core.crypto.params.ECKeyParameters)2 GOST3410Key (com.github.zhenwei.provider.jce.interfaces.GOST3410Key)2 ECDomainParameters (com.github.zhenwei.core.crypto.params.ECDomainParameters)1 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)1 ECParameterSpec (com.github.zhenwei.provider.jce.spec.ECParameterSpec)1 PublicKey (java.security.PublicKey)1