Example usage for org.bouncycastle.asn1.smime SMIMECapability aES256_CBC

List of usage examples for org.bouncycastle.asn1.smime SMIMECapability aES256_CBC

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.smime SMIMECapability aES256_CBC.

Prototype

ASN1ObjectIdentifier aES256_CBC

To view the source code for org.bouncycastle.asn1.smime SMIMECapability aES256_CBC.

Click Source Link

Usage

From source file:chapter9.SignedMailExample.java

/**
 *
 * @param key//from w w w  . j a v a  2s .c o  m
 * @param cert
 * @param certsAndCRLs
 * @param dataPart
 * @return
 * @throws Exception
 */
public static MimeMultipart createMultipartWithSignature(PrivateKey key, X509Certificate cert,
        CertStore certsAndCRLs, MimeBodyPart dataPart) throws Exception {
    //1.- Create some smime capabilities in case someone wants to respond
    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.aES256_CBC);
    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
    signedAttrs.add(new SMIMEEncryptionKeyPreferenceAttribute(SMIMEUtil.createIssuerAndSerialNumberFor(cert)));

    //2.- Set up the generator
    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(key, cert, SMIMESignedGenerator.DIGEST_SHA256, new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certsAndCRLs);

    //3.- Create the signed message
    return gen.generate(dataPart, CryptoDefs.Provider.BC.getName());
}

From source file:io.aos.crypto.spl09.SignedMailExample.java

License:Apache License

public static MimeMultipart createMultipartWithSignature(PrivateKey key, X509Certificate cert,
        CertStore certsAndCRLs, MimeBodyPart dataPart) throws Exception {
    // create some smime capabilities in case someone wants to respond
    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.aES256_CBC);
    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
    signedAttrs.add(new SMIMEEncryptionKeyPreferenceAttribute(SMIMEUtil.createIssuerAndSerialNumberFor(cert)));

    // set up the generator
    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(key, cert, SMIMESignedGenerator.DIGEST_SHA256, new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certsAndCRLs);

    // create the signed message
    return gen.generate(dataPart, "BC");
}

From source file:org.viafirma.util.SendMailUtil.java

License:Open Source License

/**
 * Crea un nuevo mail firmado. Adjuntandole el pkcs7.
 * /* w  ww  .j a v  a2s.  c o  m*/
 * @param key
 *            Clave privada con la que se realiza el proceso de firma.
 * @param cert
 *            Certificado utilizado.
 * @param certsAndCRLs
 *            Camino de confianza.
 * @param dataPart
 *            Cuerpo del email.
 * @return Mail firmado.
 * @throws CertStoreException
 * @throws SMIMEException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws CertificateParsingException
 */
private MimeMultipart createMultipartWithSignature(PrivateKey key, X509Certificate cert, CertStore certsAndCRLs,
        MimeBodyPart dataPart) throws CertStoreException, SMIMEException, NoSuchAlgorithmException,
        NoSuchProviderException, CertificateParsingException

{
    // Aadimos los tipos soportados
    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.aES256_CBC);
    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);
    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
    signedAttrs.add(new SMIMEEncryptionKeyPreferenceAttribute(SMIMEUtil.createIssuerAndSerialNumberFor(cert)));

    // Creamos el generador
    SMIMESignedGenerator generador = new SMIMESignedGenerator();

    // Establecemos la clave privada y el mtodo de firma
    generador.addSigner(key, cert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);

    // Aadimos el camino de confianza adjuntado en el mail.
    generador.addCertificatesAndCRLs(certsAndCRLs);

    // Generamos el mail firmado.
    MimeMultipart mensajeFirmado = generador.generate(dataPart, BouncyCastleProvider.PROVIDER_NAME);

    // multipart/mixed; boundary="----=_Part_2_29796765.1208556677256"
    try {

        String contentType = mensajeFirmado.getBodyPart(0).getContentType();
        contentType = contentType.replaceAll("multipart/mixed", "multipart/alternative");
        mensajeFirmado.getBodyPart(0).setHeader("Content-Type", contentType);
        // contentType =mensajeFirmado.getContentType();
        // contentType=contentType.replaceAll("application/pkcs7-signature",
        // "application/x-pkcs7-signature");
        // mensajeFirmado.getContentType();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return mensajeFirmado;
}

From source file:utils.Utils.java

License:Apache License

public static MimeMultipart createMultipartWithSignature(PrivateKey key, X509Certificate cert,
        CertStore certsAndCRLs, MimeBodyPart dataPart) throws Exception {

    // create some smime capabilities in case someone wants to respond
    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.aES256_CBC);
    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
    signedAttrs.add(new SMIMEEncryptionKeyPreferenceAttribute(SMIMEUtil.createIssuerAndSerialNumberFor(cert)));

    // set up the generator
    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSigner(key, cert, SMIMESignedGenerator.DIGEST_SHA256, new AttributeTable(signedAttrs), null);

    gen.addCertificatesAndCRLs(certsAndCRLs);

    // create the signed message
    //        return new MimeMultipart();
    return gen.generate(dataPart, "BC");
}

From source file:utils.Utils.java

License:Apache License

public static MimeMultipart createMultipartWithSignature(PrivateKey key, X509Certificate cert,
        CertStore certsAndCRLs, MimeBodyPart dataPart, String algorithm) throws Exception {

    // create some smime capabilities in case someone wants to respond
    ASN1EncodableVector signedAttrs = new ASN1EncodableVector();
    SMIMECapabilityVector caps = new SMIMECapabilityVector();

    caps.addCapability(SMIMECapability.aES256_CBC);
    caps.addCapability(SMIMECapability.dES_EDE3_CBC);
    caps.addCapability(SMIMECapability.rC2_CBC, 128);

    signedAttrs.add(new SMIMECapabilitiesAttribute(caps));
    signedAttrs.add(new SMIMEEncryptionKeyPreferenceAttribute(SMIMEUtil.createIssuerAndSerialNumberFor(cert)));

    // set up the generator
    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    if (algorithm.equals("SHA-1")) {
        gen.addSigner(key, cert, SMIMESignedGenerator.DIGEST_SHA1, new AttributeTable(signedAttrs), null);
    } else if (algorithm.equals("MD5")) {
        gen.addSigner(key, cert, SMIMESignedGenerator.DIGEST_MD5, new AttributeTable(signedAttrs), null);
    } else {/*from  w w  w . j  a  va 2  s. c o m*/
        gen.addSigner(key, cert, SMIMESignedGenerator.DIGEST_SHA256, new AttributeTable(signedAttrs), null);
    }

    gen.addCertificatesAndCRLs(certsAndCRLs);

    return gen.generate(dataPart, "BC");
}