Examples of BerOctetString


Examples of com.day.ldap.ber.stream.BEROctetString

     * Retrieves the ber representation.
     * @return ber representation
     */
    public BERElement getBERElement() {
        BERSequence seq = new BERSequence();
        seq.addElement(new BEROctetString(m_type));
        seq.addElement(new BEROctetString(m_val));
        return seq;
    }
View Full Code Here

Examples of org.bouncycastle.asn1.BEROctetString

            SafeBag kBag = new SafeBag(pkcs8ShroudedKeyBag, kInfo.toASN1Primitive(), new DERSet(kName));
            keyS.add(kBag);
        }

        byte[] keySEncoded = new DERSequence(keyS).getEncoded(ASN1Encoding.DER);
        BEROctetString keyString = new BEROctetString(keySEncoded);

        //
        // certificate processing
        //
        byte[] cSalt = new byte[SALT_SIZE];

        random.nextBytes(cSalt);

        ASN1EncodableVector certSeq = new ASN1EncodableVector();
        PKCS12PBEParams cParams = new PKCS12PBEParams(cSalt, MIN_ITERATIONS);
        AlgorithmIdentifier cAlgId = new AlgorithmIdentifier(certAlgorithm, cParams.toASN1Primitive());
        Hashtable doneCerts = new Hashtable();

        Enumeration cs = keys.keys();
        while (cs.hasMoreElements())
        {
            try
            {
                String name = (String)cs.nextElement();
                Certificate cert = engineGetCertificate(name);
                boolean cAttrSet = false;
                CertBag cBag = new CertBag(
                    x509Certificate,
                    new DEROctetString(cert.getEncoded()));
                ASN1EncodableVector fName = new ASN1EncodableVector();

                if (cert instanceof PKCS12BagAttributeCarrier)
                {
                    PKCS12BagAttributeCarrier bagAttrs = (PKCS12BagAttributeCarrier)cert;
                    //
                    // make sure we are using the local alias on store
                    //
                    DERBMPString nm = (DERBMPString)bagAttrs.getBagAttribute(pkcs_9_at_friendlyName);
                    if (nm == null || !nm.getString().equals(name))
                    {
                        bagAttrs.setBagAttribute(pkcs_9_at_friendlyName, new DERBMPString(name));
                    }

                    //
                    // make sure we have a local key-id
                    //
                    if (bagAttrs.getBagAttribute(pkcs_9_at_localKeyId) == null)
                    {
                        bagAttrs.setBagAttribute(pkcs_9_at_localKeyId, createSubjectKeyId(cert.getPublicKey()));
                    }

                    Enumeration e = bagAttrs.getBagAttributeKeys();

                    while (e.hasMoreElements())
                    {
                        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement();
                        ASN1EncodableVector fSeq = new ASN1EncodableVector();

                        fSeq.add(oid);
                        fSeq.add(new DERSet(bagAttrs.getBagAttribute(oid)));
                        fName.add(new DERSequence(fSeq));

                        cAttrSet = true;
                    }
                }

                if (!cAttrSet)
                {
                    ASN1EncodableVector fSeq = new ASN1EncodableVector();

                    fSeq.add(pkcs_9_at_localKeyId);
                    fSeq.add(new DERSet(createSubjectKeyId(cert.getPublicKey())));
                    fName.add(new DERSequence(fSeq));

                    fSeq = new ASN1EncodableVector();

                    fSeq.add(pkcs_9_at_friendlyName);
                    fSeq.add(new DERSet(new DERBMPString(name)));

                    fName.add(new DERSequence(fSeq));
                }

                SafeBag sBag = new SafeBag(certBag, cBag.toASN1Primitive(), new DERSet(fName));

                certSeq.add(sBag);

                doneCerts.put(cert, cert);
            }
            catch (CertificateEncodingException e)
            {
                throw new IOException("Error encoding certificate: " + e.toString());
            }
        }

        cs = certs.keys();
        while (cs.hasMoreElements())
        {
            try
            {
                String certId = (String)cs.nextElement();
                Certificate cert = (Certificate)certs.get(certId);
                boolean cAttrSet = false;

                if (keys.get(certId) != null)
                {
                    continue;
                }

                CertBag cBag = new CertBag(
                    x509Certificate,
                    new DEROctetString(cert.getEncoded()));
                ASN1EncodableVector fName = new ASN1EncodableVector();

                if (cert instanceof PKCS12BagAttributeCarrier)
                {
                    PKCS12BagAttributeCarrier bagAttrs = (PKCS12BagAttributeCarrier)cert;
                    //
                    // make sure we are using the local alias on store
                    //
                    DERBMPString nm = (DERBMPString)bagAttrs.getBagAttribute(pkcs_9_at_friendlyName);
                    if (nm == null || !nm.getString().equals(certId))
                    {
                        bagAttrs.setBagAttribute(pkcs_9_at_friendlyName, new DERBMPString(certId));
                    }

                    Enumeration e = bagAttrs.getBagAttributeKeys();

                    while (e.hasMoreElements())
                    {
                        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement();

                        // a certificate not immediately linked to a key doesn't require
                        // a localKeyID and will confuse some PKCS12 implementations.
                        //
                        // If we find one, we'll prune it out.
                        if (oid.equals(PKCSObjectIdentifiers.pkcs_9_at_localKeyId))
                        {
                            continue;
                        }

                        ASN1EncodableVector fSeq = new ASN1EncodableVector();

                        fSeq.add(oid);
                        fSeq.add(new DERSet(bagAttrs.getBagAttribute(oid)));
                        fName.add(new DERSequence(fSeq));

                        cAttrSet = true;
                    }
                }

                if (!cAttrSet)
                {
                    ASN1EncodableVector fSeq = new ASN1EncodableVector();

                    fSeq.add(pkcs_9_at_friendlyName);
                    fSeq.add(new DERSet(new DERBMPString(certId)));

                    fName.add(new DERSequence(fSeq));
                }

                SafeBag sBag = new SafeBag(certBag, cBag.toASN1Primitive(), new DERSet(fName));

                certSeq.add(sBag);

                doneCerts.put(cert, cert);
            }
            catch (CertificateEncodingException e)
            {
                throw new IOException("Error encoding certificate: " + e.toString());
            }
        }

        cs = chainCerts.keys();
        while (cs.hasMoreElements())
        {
            try
            {
                CertId certId = (CertId)cs.nextElement();
                Certificate cert = (Certificate)chainCerts.get(certId);

                if (doneCerts.get(cert) != null)
                {
                    continue;
                }

                CertBag cBag = new CertBag(
                    x509Certificate,
                    new DEROctetString(cert.getEncoded()));
                ASN1EncodableVector fName = new ASN1EncodableVector();

                if (cert instanceof PKCS12BagAttributeCarrier)
                {
                    PKCS12BagAttributeCarrier bagAttrs = (PKCS12BagAttributeCarrier)cert;
                    Enumeration e = bagAttrs.getBagAttributeKeys();

                    while (e.hasMoreElements())
                    {
                        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement();

                        // a certificate not immediately linked to a key doesn't require
                        // a localKeyID and will confuse some PKCS12 implementations.
                        //
                        // If we find one, we'll prune it out.
                        if (oid.equals(PKCSObjectIdentifiers.pkcs_9_at_localKeyId))
                        {
                            continue;
                        }

                        ASN1EncodableVector fSeq = new ASN1EncodableVector();

                        fSeq.add(oid);
                        fSeq.add(new DERSet(bagAttrs.getBagAttribute(oid)));
                        fName.add(new DERSequence(fSeq));
                    }
                }

                SafeBag sBag = new SafeBag(certBag, cBag.toASN1Primitive(), new DERSet(fName));

                certSeq.add(sBag);
            }
            catch (CertificateEncodingException e)
            {
                throw new IOException("Error encoding certificate: " + e.toString());
            }
        }

        byte[] certSeqEncoded = new DERSequence(certSeq).getEncoded(ASN1Encoding.DER);
        byte[] certBytes = cryptData(true, cAlgId, password, false, certSeqEncoded);
        EncryptedData cInfo = new EncryptedData(data, cAlgId, new BEROctetString(certBytes));

        ContentInfo[] info = new ContentInfo[]
            {
                new ContentInfo(data, keyString),
                new ContentInfo(encryptedData, cInfo.toASN1Primitive())
            };

        AuthenticatedSafe auth = new AuthenticatedSafe(info);

        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        DEROutputStream asn1Out;
        if (useDEREncoding)
        {
            asn1Out = new DEROutputStream(bOut);
        }
        else
        {
            asn1Out = new BEROutputStream(bOut);
        }

        asn1Out.writeObject(auth);

        byte[] pkg = bOut.toByteArray();

        ContentInfo mainInfo = new ContentInfo(data, new BEROctetString(pkg));

        //
        // create the mac
        //
        byte[] mSalt = new byte[20];
View Full Code Here

Examples of org.bouncycastle.asn1.BEROctetString

  public byte[] wrap(final byte[] data, final byte[] signature) throws IOException {
    DERSequence derSequence = (DERSequence) BouncyCastleProviderHelper.toASN1Primitive(signature);
    ContentInfo signatureContentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = SignedData.getInstance(signatureContentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BEROctetString(data));
    SignedData dataSignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, dataSignedData);
    return fullContentInfo.getEncoded();
  }
View Full Code Here

Examples of org.bouncycastle.asn1.BEROctetString

  public byte[] wrap(final byte[] data, final byte[] signature) throws IOException {
    DERSequence derSequence = (DERSequence) BouncyCastleProviderHelper.toASN1Primitive(signature);
    ContentInfo signatureContentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = SignedData.getInstance(signatureContentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BEROctetString(data));
    SignedData dataSignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, dataSignedData);
    return fullContentInfo.getEncoded();
  }
View Full Code Here

Examples of org.bouncycastle.asn1.BEROctetString

  public byte[] wrap(final byte[] data, final byte[] signature) throws IOException {
    DERSequence derSequence = (DERSequence) BouncyCastleProviderHelper.toASN1Primitive(signature);
    ContentInfo signatureContentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = SignedData.getInstance(signatureContentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BEROctetString(data));
    SignedData dataSignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, dataSignedData);
    return fullContentInfo.getEncoded();
  }
View Full Code Here

Examples of org.bouncycastle.sasn1.BerOctetString

      
       out.close();
      
       Asn1InputStream aIn = new Asn1InputStream(bOut.toByteArray());
      
       BerOctetString s = (BerOctetString)aIn.readObject();
      
       InputStream in = s.getOctetStream();
       int         count = 0;
      
       while (in.read() >= 0)
       {
           count++;
View Full Code Here

Examples of org.bouncycastle.sasn1.BerOctetString

      
       out.close();
      
       Asn1InputStream aIn = new Asn1InputStream(bOut.toByteArray());
      
       BerOctetString s = (BerOctetString)aIn.readObject();
      
       InputStream in = s.getOctetStream();
       int         count = 0;
      
       while (in.read() >= 0)
       {
           count++;
View Full Code Here

Examples of org.bouncycastle.sasn1.BerOctetString

      
       Asn1InputStream aIn = new Asn1InputStream(bOut.toByteArray());
      
       BerSequence     sq = (BerSequence)aIn.readObject();
      
       BerOctetString s = (BerOctetString)sq.readObject();
      
       Asn1InputStream aIn2 = new Asn1InputStream(s.getOctetStream());
      
       BerSequence sq2 = (BerSequence)aIn2.readObject();
      
       BerOctetString inS = (BerOctetString)sq2.readObject();
      
       InputStream in = inS.getOctetStream();
       int         count = 0;
      
       while (in.read() >= 0)
       {
           count++;
View Full Code Here

Examples of org.hxzon.asn1.core.type.BerOctetString

            break;
        case Tag.UNIVERSAL | Tag.OBJECTID:
            node = new BerOID();
            break;
        case Tag.UNIVERSAL | Tag.OCTETSTRING:
            node = new BerOctetString();
            break;
        case Tag.UNIVERSAL | Tag.PRINTABLESTRING:
            node = new BerPrintableString();
            break;
        case Tag.UNIVERSAL | Tag.REAL:
View Full Code Here

Examples of org.hxzon.asn1.core.type.BerOctetString

    public static BerNode createBerUtf8String(String name, String display, int tag, BerInputStream stream) {
        return new BerUTF8String().init(name, display, tag, stream);
    }

    public static BerNode createBerOctetString(String name, String display, int tag, BerInputStream stream) {
        return new BerOctetString().init(name, display, tag, stream);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.