Package codec.pkcs7

Examples of codec.pkcs7.ContentInfo


      throws IOException, ASN1Exception, GeneralSecurityException {
  // byte[] encodedData;
  ByteArrayInputStream bais;
  PBEKeySpec pbeSpec = null;
  byte[] data = null;
  EncryptedData encData = null;

  if (((ContentInfo) this.get(i)).getContent() instanceof EncryptedData) {
      encData = (EncryptedData) ((ContentInfo) this.get(i)).getContent();
  } else {
      System.out
        .println("This bag is public-key protected or not protected at all.");
      return null;
  }
  // "PbeWithSHAAnd40BitRC2_CBC";
  String algName = encData.getAlgorithm();

  // Create the PBEBMPKey ;
  pbeSpec = new PBEKeySpec(passwd);
  SecretKeyFactory skf = null;
  skf = SecretKeyFactory.getInstance(algName);
  SecretKey pbeKey = skf.generateSecret(pbeSpec);
  encData.init(pbeKey);
  data = encData.getData();
  bais = new ByteArrayInputStream(data);
  SafeContents safe = new SafeContents();
  BERDecoder decoder = new BERDecoder(bais);
  safe.decode(decoder);
  bais.close();
View Full Code Here


  SecretKey pbekey = skf.generateSecret(pbeSpec);

  // System.out.println("The pbe key for encrypting");
  // System.out.println(new ASN1OctetString(pbekey.getEncoded()));
  // make an EncryptedData and put it in a ContentInfo
  EncryptedData ecd = new EncryptedData(algorithm, pbekey, params);
  ecd.setData(bais);
  bais.close();

  ContentInfo cinfo = new ContentInfo();
  cinfo.setContent(new codec.asn1.ASN1ObjectIdentifier(
    "1.2.840.113549.1.7.6"), ecd);
View Full Code Here

      java.security.cert.X509Certificate cert) throws IOException,
      ASN1Exception, GeneralSecurityException, NoSuchElementException {
  ByteArrayInputStream bais;

  ContentInfo cinfo = (ContentInfo) this.get(i);
  EnvelopedData envData = null;
  if (cinfo.getContent() instanceof EnvelopedData) {
      envData = (EnvelopedData) cinfo.getContent();
  } else {
      System.out
        .println("This bag is password protected or not protected at all.");
      return null;
  }

  envData.init(cert, key);
  byte[] data = envData.getData();

  bais = new ByteArrayInputStream(data);
  SafeContents safe = new SafeContents();
  BERDecoder decoder = new BERDecoder(bais);
  safe.decode(decoder);
View Full Code Here

  safe.encode(encoder);
  bais = new ByteArrayInputStream(baos.toByteArray());
  baos.close();

  // Make an envelopedData and put it in a ContentInfo
  EnvelopedData edata = new EnvelopedData(key, algorithm, params);
  edata.setData(bais);
  bais.close();
  for (int i = 0; i < cert.length; i++) {
      edata.addRecipient(cert[i]);
  }

  ContentInfo cinfo = new ContentInfo(edata);
  return cinfo;
    }
View Full Code Here

            if (encodingsArr[0].equals(encoding)) {
                // generate the object from PkiPath encoded form
                return (X509CertPathImpl) ASN1.decode(in);
            } else {
                // generate the object from PKCS #7 encoded form
                ContentInfo ci = (ContentInfo) ContentInfo.ASN1.decode(in);
                SignedData sd = ci.getSignedData();
                if (sd == null) {
                    throw new CertificateException(
                        Messages.getString("security.160")); //$NON-NLS-1$
                }
                List certs = sd.getCertificates();
                if (certs == null) {
                    // empty chain of certificates
                    certs = new ArrayList();
                }
                List result = new ArrayList();
                for (int i=0; i<certs.size(); i++) {
                    result.add(new X509CertImpl((Certificate) certs.get(i)));
                }
                return new X509CertPathImpl(result, PKCS7, ci.getEncoded());
            }
        } catch (IOException e) {
            throw new CertificateException(Messages.getString("security.15E", //$NON-NLS-1$
                    e.getMessage()));
        }
View Full Code Here

            if (encodingsArr[0].equals(encoding)) {
                // generate the object from PkiPath encoded form
                return (X509CertPathImpl) ASN1.decode(in);
            } else {
                // generate the object from PKCS #7 encoded form
                ContentInfo ci = (ContentInfo) ContentInfo.ASN1.decode(in);
                SignedData sd = ci.getSignedData();
                if (sd == null) {
                    throw new CertificateException(
                        Messages.getString("security.160")); //$NON-NLS-1$
                }
                List certs = sd.getCertificates();
                if (certs == null) {
                    certs = new ArrayList();
                }
                List result = new ArrayList();
                for (int i=0; i<certs.size(); i++) {
                    result.add(new X509CertImpl((Certificate) certs.get(i)));
                }
                return new X509CertPathImpl(result, PKCS7, ci.getEncoded());
            }
        } catch (IOException e) {
            throw new CertificateException(Messages.getString("security.15E", //$NON-NLS-1$
                    e.getMessage()));
        }
View Full Code Here

            return getEncoded();
        } else {
            // PKCS7 encoded form
            if (pkcs7Encoding == null) {
                SignedData sd = new SignedData(1, new ArrayList(),
                        new ContentInfo(ContentInfo.DATA, null), certificates,
                        null, new ArrayList());
                ContentInfo ci = new ContentInfo(ContentInfo.SIGNED_DATA, sd);
                pkcs7Encoding = ci.getEncoded();
            }
            byte[] result = new byte[pkiPathEncoding.length];
            System.arraycopy(pkcs7Encoding, 0, result, 0,
                                        pkcs7Encoding.length);
            return result;
View Full Code Here

                        Messages.getString("security.155")); //$NON-NLS-1$
            }
            // else: check if it is PKCS7
            if (second_asn1_tag == ASN1Constants.TAG_OID) {
                // it is PKCS7 ContentInfo structure, so decode it
                ContentInfo info = (ContentInfo)
                    ((encoding != null)
                        ? ContentInfo.ASN1.decode(encoding)
                        : ContentInfo.ASN1.decode(inStream));
                // retrieve SignedData
                SignedData data = info.getSignedData();
                if (data == null) {
                    throw new CertificateException(
                            Messages.getString("security.154")); //$NON-NLS-1$
                }
                List certs = data.getCertificates();
View Full Code Here

                        Messages.getString("security.155")); //$NON-NLS-1$
            }
            // else: check if it is PKCS7
            if (second_asn1_tag == ASN1Constants.TAG_OID) {
                // it is PKCS7 ContentInfo structure, so decode it
                ContentInfo info = (ContentInfo)
                    ((encoding != null)
                        ? ContentInfo.ASN1.decode(encoding)
                        : ContentInfo.ASN1.decode(inStream));
                // retrieve SignedData
                SignedData data = info.getSignedData();
                if (data == null) {
                    throw new CRLException(
                            Messages.getString("security.154")); //$NON-NLS-1$
                }
                List crls = data.getCRLs();
View Full Code Here

        SignerInfo sigInfo = new SignerInfo(1, issuerAndSerialNumber,
                new AlgorithmIdentifier(sha1), null, new AlgorithmIdentifier(
                        sha1dsa), new byte[20], null);
        // TSTInfo OID according to RFC 3161
        int[] tSTInfoOid = new int[] { 1, 2, 840, 113549, 1, 9, 16, 1, 4 };
        ContentInfo tSTInfoEncoded = new ContentInfo(tSTInfoOid,
                ASN1OctetString.getInstance().encode(
                        TSTInfo.ASN1.encode(tSTInfo)));
        SignedData tokenContent = new SignedData(1, Collections
                .singletonList(new AlgorithmIdentifier(sha1)), tSTInfoEncoded,
                null, null, Collections.singletonList(sigInfo));
        ContentInfo timeStampToken = new ContentInfo(ContentInfo.SIGNED_DATA,
                tokenContent);
       
        TimeStampResp response = new TimeStampResp(status, timeStampToken);
       
        byte [] encoding = TimeStampResp.ASN1.encode(response);
        TimeStampResp decoded = (TimeStampResp) TimeStampResp.ASN1
                .decode(encoding);

        // deeper checks are performed in the corresponding unit tests
        assertTrue("Decoded status is incorrect", Arrays.equals(
                PKIStatusInfo.ASN1.encode(status), PKIStatusInfo.ASN1
                        .encode(decoded.getStatus())));
        assertTrue("Decoded timeStampToken is incorrect", Arrays.equals(
                timeStampToken.getEncoded(), decoded.getTimeStampToken()
                        .getEncoded()));
    }
View Full Code Here

TOP

Related Classes of codec.pkcs7.ContentInfo

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.