public void testSHA224WithRSAParserEncryptedWithDES() throws Exception {
    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator();

    gen.addSignerInfoGenerator(
        new JcaSimpleSignerInfoGeneratorBuilder()
            .setProvider(BC)
            .setSignedAttributeGenerator(
                new DefaultSignedAttributeTableGenerator(new AttributeTable(signedAttrs)))
            .build("SHA224withRSA", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    MimeMultipart smm = gen.generate(msg);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);

    certs = s.getCertificates();

    assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());

    verifyMessageBytes(msg, s.getContent());

    verifySigners(certs, s.getSignerInfos());
  }
  private void rsaPSSTest(String digest, String digestOID) throws Exception {
    MimeMultipart smm = generateMultiPartRsaPSS(digest, msg, null);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);
    Store certs = s.getCertificates();

    assertEquals(getDigestOid(s.getSignerInfos()), digestOID);

    verifyMessageBytes(msg, s.getContent());

    verifySigners(certs, s.getSignerInfos());
  }
  public void testSHA224WithRSAParser() throws Exception {
    MimeMultipart smm =
        generateMultiPartRsa("SHA224withRSA", msg, SMIMESignedGenerator.RFC3851_MICALGS);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);
    Store certs = s.getCertificates();

    assertEquals(getDigestOid(s.getSignerInfos()), NISTObjectIdentifiers.id_sha224.toString());

    verifyMessageBytes(msg, s.getContent());

    verifySigners(certs, s.getSignerInfos());
  }
  public void testSignAttachmentOnly() throws Exception {
    MimeMessage m = loadMessage("attachonly.eml");

    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSignerInfoGenerator(
        new JcaSimpleSignerInfoGeneratorBuilder()
            .setProvider(BC)
            .setSignedAttributeGenerator(new AttributeTable(signedAttrs))
            .build("SHA1withRSA", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    MimeMultipart mm = gen.generate(m);

    SMIMESigned s = new SMIMESigned(mm);

    verifySigners(s.getCertificates(), s.getSignerInfos());

    SMIMESignedParser sp =
        new SMIMESignedParser(new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), mm);

    verifySigners(sp.getCertificates(), sp.getSignerInfos());
  }
  public void testMimeMultipartBinaryParserGetMimeContent() throws Exception {
    MimeBodyPart m = createMultipartMessage();

    List certList = new ArrayList();

    certList.add(_signCert);
    certList.add(_origCert);

    Store certs = new JcaCertStore(certList);

    ASN1EncodableVector signedAttrs = generateSignedAttributes();

    SMIMESignedGenerator gen = new SMIMESignedGenerator("binary");

    gen.addSignerInfoGenerator(
        new JcaSimpleSignerInfoGeneratorBuilder()
            .setProvider(BC)
            .setSignedAttributeGenerator(new AttributeTable(signedAttrs))
            .build("SHA1withRSA", _signKP.getPrivate(), _signCert));
    gen.addCertificates(certs);

    MimeMultipart mm = gen.generate(m);

    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), mm, "binary");

    verifySigners(s.getCertificates(), s.getSignerInfos());

    MimeMessage bp = s.getContentAsMimeMessage(Session.getDefaultInstance(new Properties()));
  }
  public void testRawAS2Parser() throws Exception {
    MimeMessage message = loadMessage("rawAS2.message");

    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(),
            (MimeMultipart) message.getContent());

    verifySigners(s.getCertificates(), s.getSignerInfos());
  }
  public void testSHA256WithRSABinaryWithParser() throws Exception {
    MimeBodyPart msg = generateBinaryPart();
    MimeMultipart smm =
        generateMultiPartRsa("SHA256withRSA", msg, SMIMESignedGenerator.RFC3851_MICALGS);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), smm);

    verifyMessageBytes(msg, s.getContent());

    verifySigners(s.getCertificates(), s.getSignerInfos());
  }
  public void testSHA1WithRSAEncapsulatedParser() throws Exception {
    MimeBodyPart res = generateEncapsulatedRsa("SHA1withRSA", msg);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), res);

    FileBackedMimeBodyPart content = (FileBackedMimeBodyPart) s.getContent();

    verifyMessageBytes(msg, content);

    content.dispose();

    verifySigners(s.getCertificates(), s.getSignerInfos());

    s.close();
  }
  public void testSHA1WithRSAEncapsulatedParserAndFile() throws Exception {
    File tmp = File.createTempFile("bcTest", ".mime");
    MimeBodyPart res = generateEncapsulatedRsa("SHA1withRSA", msg);
    SMIMESignedParser s =
        new SMIMESignedParser(
            new JcaDigestCalculatorProviderBuilder().setProvider(BC).build(), res, tmp);
    FileBackedMimeBodyPart content = (FileBackedMimeBodyPart) s.getContent();

    verifyMessageBytes(msg, s.getContent());

    verifySigners(s.getCertificates(), s.getSignerInfos());

    assertTrue(tmp.exists());

    s.close();

    content.dispose();

    assertFalse(tmp.exists());
  }