Search in sources :

Example 36 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class DSABase method engineSign.

protected byte[] engineSign() throws SignatureException {
    byte[] hash = new byte[digest.getDigestSize()];
    digest.doFinal(hash, 0);
    try {
        BigInteger[] sig = signer.generateSignature(hash);
        return encoder.encode(sig[0], sig[1]);
    } catch (Exception e) {
        throw new SignatureException(e.toString());
    }
}
Also used : BigInteger(java.math.BigInteger) SignatureException(java.security.SignatureException) SignatureException(java.security.SignatureException)

Example 37 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class DSASigner method engineVerify.

protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
    byte[] hash = new byte[digest.getDigestSize()];
    digest.doFinal(hash, 0);
    BigInteger[] sig;
    try {
        sig = derDecode(sigBytes);
    } catch (Exception e) {
        throw new SignatureException("error decoding signature bytes.");
    }
    return signer.verifySignature(hash, sig[0], sig[1]);
}
Also used : BigInteger(java.math.BigInteger) SignatureException(java.security.SignatureException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Example 38 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class OpenSSLX509Certificate method verifyInternal.

private void verifyInternal(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
    String sigAlg = getSigAlgName();
    if (sigAlg == null) {
        sigAlg = getSigAlgOID();
    }
    final Signature sig;
    if (sigProvider == null) {
        sig = Signature.getInstance(sigAlg);
    } else {
        sig = Signature.getInstance(sigAlg, sigProvider);
    }
    sig.initVerify(key);
    sig.update(getTBSCertificate());
    if (!sig.verify(getSignature())) {
        throw new SignatureException("signature did not verify");
    }
}
Also used : Signature(java.security.Signature) SignatureException(java.security.SignatureException)

Example 39 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class SignatureTest method testVerify_NONEwithRSA_Key_SignatureTooLarge_Failure.

public void testVerify_NONEwithRSA_Key_SignatureTooLarge_Failure() throws Exception {
    KeyFactory kf = KeyFactory.getInstance("RSA");
    RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
    PublicKey pubKey = kf.generatePublic(pubKeySpec);
    Signature sig = Signature.getInstance("NONEwithRSA");
    sig.initVerify(pubKey);
    sig.update(Vector1Data);
    byte[] invalidSignature = new byte[NONEwithRSA_Vector1Signature.length * 2];
    System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature, 0, NONEwithRSA_Vector1Signature.length);
    System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature, NONEwithRSA_Vector1Signature.length, NONEwithRSA_Vector1Signature.length);
    try {
        sig.verify(invalidSignature);
        fail("Should throw exception when signature is too large");
    } catch (SignatureException expected) {
    }
}
Also used : PublicKey(java.security.PublicKey) Signature(java.security.Signature) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) SignatureException(java.security.SignatureException) KeyFactory(java.security.KeyFactory)

Example 40 with SignatureException

use of java.security.SignatureException in project robovm by robovm.

the class X509CRLObject method verify.

public void verify(PublicKey key, String sigProvider) throws CRLException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
    if (!c.getSignatureAlgorithm().equals(c.getTBSCertList().getSignature())) {
        throw new CRLException("Signature algorithm on CertificateList does not match TBSCertList.");
    }
    Signature sig;
    if (sigProvider != null) {
        sig = Signature.getInstance(getSigAlgName(), sigProvider);
    } else {
        sig = Signature.getInstance(getSigAlgName());
    }
    sig.initVerify(key);
    sig.update(this.getTBSCertList());
    if (!sig.verify(this.getSignature())) {
        throw new SignatureException("CRL does not verify with supplied public key.");
    }
}
Also used : Signature(java.security.Signature) SignatureException(java.security.SignatureException) CRLException(java.security.cert.CRLException)

Aggregations

SignatureException (java.security.SignatureException)329 InvalidKeyException (java.security.InvalidKeyException)171 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)132 Signature (java.security.Signature)132 IOException (java.io.IOException)75 PublicKey (java.security.PublicKey)53 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)39 X509Certificate (java.security.cert.X509Certificate)33 BigInteger (java.math.BigInteger)32 CertificateException (java.security.cert.CertificateException)31 NoSuchProviderException (java.security.NoSuchProviderException)29 PrivateKey (java.security.PrivateKey)25 ByteArrayInputStream (java.io.ByteArrayInputStream)17 KeyFactory (java.security.KeyFactory)15 ArrayList (java.util.ArrayList)15 MySignature1 (org.apache.harmony.security.tests.support.MySignature1)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)12 GeneralSecurityException (java.security.GeneralSecurityException)12 MessageDigest (java.security.MessageDigest)12