Search in sources :

Example 26 with Signature

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

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 = Signature.getInstance(getSigAlgName(), sigProvider);
    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)

Example 27 with Signature

use of java.security.Signature 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 28 with Signature

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

the class X509CertificateObject method verify.

public final void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
    String sigName = X509SignatureUtil.getSignatureName(c.getSignatureAlgorithm());
    Signature signature = Signature.getInstance(sigName, sigProvider);
    checkSignature(key, signature);
}
Also used : Signature(java.security.Signature) DERBitString(org.bouncycastle.asn1.DERBitString) DERIA5String(org.bouncycastle.asn1.DERIA5String)

Example 29 with Signature

use of java.security.Signature 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)

Example 30 with Signature

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

the class SigningProcessor method process.

public void process(Exchange exchange) throws Exception {
    Signature service = initSignatureService(exchange);
    calculateSignature(exchange, service);
    byte[] signature = service.sign();
    Message in = exchange.getIn();
    clearMessageHeaders(in);
    Message out = exchange.getOut();
    out.copyFrom(in);
    out.setHeader(config.getSignatureHeaderName(), new Base64().encode(signature));
}
Also used : Base64(org.apache.commons.codec.binary.Base64) Message(org.apache.camel.Message) Signature(java.security.Signature)

Aggregations

Signature (java.security.Signature)261 SignatureException (java.security.SignatureException)84 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)70 InvalidKeyException (java.security.InvalidKeyException)61 PublicKey (java.security.PublicKey)61 PrivateKey (java.security.PrivateKey)43 IOException (java.io.IOException)42 KeyFactory (java.security.KeyFactory)41 X509Certificate (java.security.cert.X509Certificate)26 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)23 KeyPair (java.security.KeyPair)19 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)19 GeneralSecurityException (java.security.GeneralSecurityException)16 KeyPairGenerator (java.security.KeyPairGenerator)16 MySignature1 (org.apache.harmony.security.tests.support.MySignature1)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 BigInteger (java.math.BigInteger)14 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)14 CertificateException (java.security.cert.CertificateException)14 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)14