Search in sources :

Example 46 with InvalidKeyException

use of java.security.InvalidKeyException in project XobotOS by xamarin.

the class X509CertificateObject method verify.

public final void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
    Signature signature;
    String sigName = X509SignatureUtil.getSignatureName(c.getSignatureAlgorithm());
    try {
        signature = Signature.getInstance(sigName, BouncyCastleProvider.PROVIDER_NAME);
    } catch (Exception e) {
        signature = Signature.getInstance(sigName);
    }
    checkSignature(key, signature);
}
Also used : Signature(java.security.Signature) DERBitString(org.bouncycastle.asn1.DERBitString) DERIA5String(org.bouncycastle.asn1.DERIA5String) CertificateExpiredException(java.security.cert.CertificateExpiredException) SignatureException(java.security.SignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CertificateEncodingException(java.security.cert.CertificateEncodingException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 47 with InvalidKeyException

use of java.security.InvalidKeyException in project XobotOS by xamarin.

the class ECUtil method generatePrivateKeyParameter.

public static AsymmetricKeyParameter generatePrivateKeyParameter(PrivateKey key) throws InvalidKeyException {
    if (key instanceof ECPrivateKey) {
        ECPrivateKey k = (ECPrivateKey) key;
        ECParameterSpec s = k.getParameters();
        if (s == null) {
            s = ProviderUtil.getEcImplicitlyCa();
        }
        return new ECPrivateKeyParameters(k.getD(), new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
    }
    throw new InvalidKeyException("can't identify EC private key.");
}
Also used : ECPrivateKey(org.bouncycastle.jce.interfaces.ECPrivateKey) ECPrivateKeyParameters(org.bouncycastle.crypto.params.ECPrivateKeyParameters) ECDomainParameters(org.bouncycastle.crypto.params.ECDomainParameters) ECParameterSpec(org.bouncycastle.jce.spec.ECParameterSpec) InvalidKeyException(java.security.InvalidKeyException)

Example 48 with InvalidKeyException

use of java.security.InvalidKeyException in project XobotOS by xamarin.

the class Signature method engineInitSign.

protected void engineInitSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException {
    CipherParameters param;
    if (privateKey instanceof ECKey) {
        param = ECUtil.generatePrivateKeyParameter(privateKey);
    } else {
        throw new InvalidKeyException("can't recognise key type in ECDSA based signer");
    }
    digest.reset();
    if (random != null) {
        signer.init(true, new ParametersWithRandom(param, random));
    } else {
        signer.init(true, param);
    }
}
Also used : CipherParameters(org.bouncycastle.crypto.CipherParameters) ParametersWithRandom(org.bouncycastle.crypto.params.ParametersWithRandom) ECKey(org.bouncycastle.jce.interfaces.ECKey) InvalidKeyException(java.security.InvalidKeyException)

Example 49 with InvalidKeyException

use of java.security.InvalidKeyException in project otter by alibaba.

the class AESUtils method encrypt.

/**
     * 加密byte数据
     * 
     * @param plainData
     * @return
     * @throws AESException
     */
public byte[] encrypt(byte[] plainData) throws AESException {
    try {
        SecretKeySpec skeySpec = new SecretKeySpec(secretKey, ENCRYPTION_ALGORITHM);
        // Instantiate the cipher
        Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        return cipher.doFinal(plainData);
    } catch (NoSuchAlgorithmException e) {
        throw new AESException(e);
    } catch (NoSuchPaddingException e) {
        throw new AESException(e);
    } catch (InvalidKeyException e) {
        throw new AESException(e);
    } catch (IllegalBlockSizeException e) {
        throw new AESException(e);
    } catch (BadPaddingException e) {
        throw new AESException(e);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException)

Example 50 with InvalidKeyException

use of java.security.InvalidKeyException in project camel by apache.

the class RSAKeyPairIdentity method getSignature.

@Override
public byte[] getSignature(byte[] data) {
    PrivateKey prvKey = keyPair.getPrivate();
    Signature sig;
    try {
        sig = Signature.getInstance("SHA1withRSA");
        sig.initSign(prvKey);
        sig.update(data);
        byte[] sshRsa = ALGORITHM_TYPE.getBytes();
        byte[] signature = sig.sign();
        byte[] result = new byte[sshRsa.length + 4 + signature.length + 4];
        int index = 0;
        byte[] intAsByteArray = ByteBuffer.allocate(4).putInt(sshRsa.length).array();
        System.arraycopy(intAsByteArray, 0, result, index, 4);
        index += 4;
        System.arraycopy(sshRsa, 0, result, index, sshRsa.length);
        index += sshRsa.length;
        intAsByteArray = ByteBuffer.allocate(4).putInt(signature.length).array();
        System.arraycopy(intAsByteArray, 0, result, index, 4);
        index += 4;
        System.arraycopy(signature, 0, result, index, signature.length);
        return result;
    } catch (NoSuchAlgorithmException e) {
        log.error("Cannot sign", e);
    } catch (InvalidKeyException e) {
        log.error("Cannot sign", e);
    } catch (SignatureException e) {
        log.error("Cannot sign", e);
    }
    return null;
}
Also used : PrivateKey(java.security.PrivateKey) Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

InvalidKeyException (java.security.InvalidKeyException)499 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)263 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)124 SignatureException (java.security.SignatureException)95 IOException (java.io.IOException)94 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)93 BadPaddingException (javax.crypto.BadPaddingException)89 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)87 Cipher (javax.crypto.Cipher)77 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)63 SecretKeySpec (javax.crypto.spec.SecretKeySpec)63 Signature (java.security.Signature)58 SecretKey (javax.crypto.SecretKey)50 PublicKey (java.security.PublicKey)49 PrivateKey (java.security.PrivateKey)47 CertificateException (java.security.cert.CertificateException)46 Mac (javax.crypto.Mac)44 IvParameterSpec (javax.crypto.spec.IvParameterSpec)41 NoSuchProviderException (java.security.NoSuchProviderException)39 KeyStoreException (java.security.KeyStoreException)33