Package org.bouncycastle.cms

Examples of org.bouncycastle.cms.CMSEnvelopedData


              }
              // First we extract the encrypted data from the CMS enveloped data contained
              // within the CMS signed data
              final CMSProcessable sp = s.getSignedContent();
              final byte content[] = (byte[])sp.getContent();
              final CMSEnvelopedData ed = new CMSEnvelopedData(content);
              final RecipientInformationStore recipients = ed.getRecipientInfos();
              final RecipientInformation recipient;
              {
                final Collection<?> c = recipients.getRecipients();
                if ( c.size() != 1 ) {
                  StressTest.this.performanceTest.getLog().error("recipients should be 1: "+c.size());
View Full Code Here


            // First we extract the encrypted data from the CMS enveloped data
            // contained
            // within the CMS signed data
            final CMSProcessable sp = s.getSignedContent();
            final byte[] content = (byte[]) sp.getContent();
            final CMSEnvelopedData ed = new CMSEnvelopedData(content);
            final RecipientInformationStore recipients = ed.getRecipientInfos();
            CertStore certstore;
            {
                Collection<RecipientInformation> c = recipients.getRecipients();
                assertEquals(c.size(), 1);
                Iterator<RecipientInformation> it = c.iterator();
View Full Code Here

        if (!responsestatus.equals(ResponseStatus.PENDING.getValue()) && messageType.equals("3")) {
            // First we extract the encrypted data from the CMS enveloped data contained
            // within the CMS signed data
            CMSProcessable sp = s.getSignedContent();
            byte[] content = (byte[])sp.getContent();
            CMSEnvelopedData ed = new CMSEnvelopedData(content);
            RecipientInformationStore recipients = ed.getRecipientInfos();
            Collection c = recipients.getRecipients();
            assertEquals(c.size(), 1);
            Iterator it = c.iterator();
            byte[] decBytes = null;
            RecipientInformation recipient = (RecipientInformation) it.next();
View Full Code Here

   
    private CMSEnvelopedData envelope(CMSProcessable envThis) throws NoSuchAlgorithmException, NoSuchProviderException, CMSException {
        CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
        // Envelope the CMS message
        edGen.addKeyTransRecipient(cacert);
        CMSEnvelopedData ed = edGen.generate(envThis, SMIMECapability.dES_CBC.getId(), "BC");
        return ed;
    }
View Full Code Here

    private byte[] wrap(byte[] envBytes, String messageType) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, CMSException, InvalidAlgorithmParameterException, CertStoreException {

        //
        // Create inner enveloped data
        //
        CMSEnvelopedData ed = envelope(new CMSProcessableByteArray(envBytes));
        log.debug("Enveloped data is " + ed.getEncoded().length + " bytes long");
        CMSProcessable msg = new CMSProcessableByteArray(ed.getEncoded());
        //
        // Create the outer signed data
        //
        CMSSignedData s = sign(msg, messageType);
       
View Full Code Here

            }
            for (int i = 0; i<recipients.size(); i++) {
                PdfObject recipient = recipients.getPdfObject(i);
                strings.remove(recipient);

                CMSEnvelopedData data = null;
                try {
                    data = new CMSEnvelopedData(recipient.getBytes());

                    Iterator<RecipientInformation> recipientCertificatesIt = data.getRecipientInfos().getRecipients().iterator();

                    while (recipientCertificatesIt.hasNext()) {
                        RecipientInformation recipientInfo = recipientCertificatesIt.next();

                        if (recipientInfo.getRID().match(certificate) && !foundRecipient) {
View Full Code Here

     
      CryptoProviderTools.installBCProviderIfNotAvailable();
       
        CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();                             
      
      CMSEnvelopedData ed;
    try {
      edGen.addKeyTransRecipient( this.getCAToken().getPublicKey(SecConst.CAKEYPURPOSE_KEYENCRYPT), this.keyId);
      ed = edGen.generate(
          new CMSProcessableByteArray(baos.toByteArray()), CMSEnvelopedDataGenerator.AES256_CBC,"BC");
    } catch (Exception e) {
            log.error("-encryptKeys: ", e);
            throw new IOException(e.getMessage());       
    }
       
   
    return ed.getEncoded();
    }
View Full Code Here

   
    return ed.getEncoded();
    }
   
    public KeyPair decryptKeys(byte[] data) throws Exception {
      CMSEnvelopedData ed = new CMSEnvelopedData(data);          
          
    RecipientInformationStore  recipients = ed.getRecipientInfos();            
      Iterator it =  recipients.getRecipients().iterator();
      RecipientInformation   recipient = (RecipientInformation) it.next();
      ObjectInputStream ois = null;
      byte[] recdata = recipient.getContent(getCAToken().getPrivateKey(SecConst.CAKEYPURPOSE_KEYENCRYPT),getCAToken().getJCEProvider());
      ois = new ObjectInputStream(new ByteArrayInputStream(recdata));
View Full Code Here

                 
      return (KeyPair) ois.readObject()
    }

  public byte[] decryptData(byte[] data, int cAKeyPurpose) throws Exception {
      CMSEnvelopedData ed = new CMSEnvelopedData(data);
    RecipientInformationStore  recipients = ed.getRecipientInfos();            
      Iterator it =  recipients.getRecipients().iterator();
      RecipientInformation   recipient = (RecipientInformation) it.next();
      byte[] recdata = recipient.getContent(getCAToken().getPrivateKey(cAKeyPurpose),getCAToken().getProvider());     
                 
      return recdata; 
View Full Code Here

  }

  public byte[] encryptData(byte[] data, int keyPurpose) throws Exception {
      CryptoProviderTools.installBCProviderIfNotAvailable();
        CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();                                    
      CMSEnvelopedData ed;
    try {
      edGen.addKeyTransRecipient( this.getCAToken().getPublicKey(keyPurpose), this.keyId);
      ed = edGen.generate(
          new CMSProcessableByteArray(data), CMSEnvelopedDataGenerator.AES256_CBC,"BC");
    } catch (Exception e) {
            log.error("-encryptKeys: ", e);
            throw new IOException(e.getMessage());       
    }       
   
    return ed.getEncoded();
  }
View Full Code Here

TOP

Related Classes of org.bouncycastle.cms.CMSEnvelopedData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.