Source Code Cross Referenced for CMSEnvelopedData.java in  » Security » Bouncy-Castle » org » bouncycastle » cms » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » Bouncy Castle » org.bouncycastle.cms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.cms;
002:
003:        import org.bouncycastle.asn1.ASN1OutputStream;
004:        import org.bouncycastle.asn1.ASN1Set;
005:        import org.bouncycastle.asn1.DEREncodable;
006:        import org.bouncycastle.asn1.cms.AttributeTable;
007:        import org.bouncycastle.asn1.cms.ContentInfo;
008:        import org.bouncycastle.asn1.cms.EncryptedContentInfo;
009:        import org.bouncycastle.asn1.cms.EnvelopedData;
010:        import org.bouncycastle.asn1.cms.KEKRecipientInfo;
011:        import org.bouncycastle.asn1.cms.KeyAgreeRecipientInfo;
012:        import org.bouncycastle.asn1.cms.KeyTransRecipientInfo;
013:        import org.bouncycastle.asn1.cms.PasswordRecipientInfo;
014:        import org.bouncycastle.asn1.cms.RecipientInfo;
015:        import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
016:
017:        import java.io.ByteArrayInputStream;
018:        import java.io.ByteArrayOutputStream;
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.security.AlgorithmParameters;
022:        import java.security.NoSuchProviderException;
023:        import java.util.ArrayList;
024:        import java.util.List;
025:
026:        /**
027:         * containing class for an CMS Enveloped Data object
028:         */
029:        public class CMSEnvelopedData {
030:            RecipientInformationStore recipientInfoStore;
031:            ContentInfo contentInfo;
032:
033:            private AlgorithmIdentifier encAlg;
034:            private ASN1Set unprotectedAttributes;
035:            private AlgorithmIdentifier _encAlg;
036:
037:            public CMSEnvelopedData(byte[] envelopedData) throws CMSException {
038:                this (CMSUtils.readContentInfo(envelopedData));
039:            }
040:
041:            public CMSEnvelopedData(InputStream envelopedData)
042:                    throws CMSException {
043:                this (CMSUtils.readContentInfo(envelopedData));
044:            }
045:
046:            public CMSEnvelopedData(ContentInfo contentInfo)
047:                    throws CMSException {
048:                this .contentInfo = contentInfo;
049:
050:                EnvelopedData envData = EnvelopedData.getInstance(contentInfo
051:                        .getContent());
052:
053:                //
054:                // read the encrypted content info
055:                //
056:                EncryptedContentInfo encInfo = envData
057:                        .getEncryptedContentInfo();
058:
059:                this ._encAlg = encInfo.getContentEncryptionAlgorithm();
060:
061:                //
062:                // load the RecepientInfoStore
063:                //
064:                ASN1Set s = envData.getRecipientInfos();
065:                List infos = new ArrayList();
066:
067:                for (int i = 0; i != s.size(); i++) {
068:                    RecipientInfo info = RecipientInfo.getInstance(s
069:                            .getObjectAt(i));
070:                    Object type = info.getInfo();
071:
072:                    if (type instanceof  KeyTransRecipientInfo) {
073:                        infos.add(new KeyTransRecipientInformation(
074:                                (KeyTransRecipientInfo) type, _encAlg,
075:                                new ByteArrayInputStream(encInfo
076:                                        .getEncryptedContent().getOctets())));
077:                    } else if (type instanceof  KEKRecipientInfo) {
078:                        infos.add(new KEKRecipientInformation(
079:                                (KEKRecipientInfo) type, _encAlg,
080:                                new ByteArrayInputStream(encInfo
081:                                        .getEncryptedContent().getOctets())));
082:                    } else if (type instanceof  KeyAgreeRecipientInfo) {
083:                        infos.add(new KeyAgreeRecipientInformation(
084:                                (KeyAgreeRecipientInfo) type, _encAlg,
085:                                new ByteArrayInputStream(encInfo
086:                                        .getEncryptedContent().getOctets())));
087:                    } else if (type instanceof  PasswordRecipientInfo) {
088:                        infos.add(new PasswordRecipientInformation(
089:                                (PasswordRecipientInfo) type, _encAlg,
090:                                new ByteArrayInputStream(encInfo
091:                                        .getEncryptedContent().getOctets())));
092:                    }
093:                }
094:
095:                this .encAlg = envData.getEncryptedContentInfo()
096:                        .getContentEncryptionAlgorithm();
097:                this .recipientInfoStore = new RecipientInformationStore(infos);
098:                this .unprotectedAttributes = envData.getUnprotectedAttrs();
099:            }
100:
101:            private byte[] encodeObj(DEREncodable obj) throws IOException {
102:                if (obj != null) {
103:                    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
104:                    ASN1OutputStream aOut = new ASN1OutputStream(bOut);
105:
106:                    aOut.writeObject(obj);
107:
108:                    return bOut.toByteArray();
109:                }
110:
111:                return null;
112:            }
113:
114:            /**
115:             * return the object identifier for the content encryption algorithm.
116:             */
117:            public String getEncryptionAlgOID() {
118:                return encAlg.getObjectId().getId();
119:            }
120:
121:            /**
122:             * return the ASN.1 encoded encryption algorithm parameters, or null if
123:             * there aren't any.
124:             */
125:            public byte[] getEncryptionAlgParams() {
126:                try {
127:                    return encodeObj(encAlg.getParameters());
128:                } catch (Exception e) {
129:                    throw new RuntimeException(
130:                            "exception getting encryption parameters " + e);
131:                }
132:            }
133:
134:            /**
135:             * Return an AlgorithmParameters object giving the encryption parameters
136:             * used to encrypt the message content.
137:             * 
138:             * @param provider the provider to generate the parameters for.
139:             * @return the parameters object, null if there is not one.
140:             * @throws CMSException if the algorithm cannot be found, or the parameters can't be parsed.
141:             * @throws NoSuchProviderException if the provider cannot be found.
142:             */
143:            public AlgorithmParameters getEncryptionAlgorithmParameters(
144:                    String provider) throws CMSException,
145:                    NoSuchProviderException {
146:                return CMSEnvelopedHelper.INSTANCE
147:                        .getEncryptionAlgorithmParameters(
148:                                getEncryptionAlgOID(),
149:                                getEncryptionAlgParams(), provider);
150:            }
151:
152:            /**
153:             * return a store of the intended recipients for this message
154:             */
155:            public RecipientInformationStore getRecipientInfos() {
156:                return recipientInfoStore;
157:            }
158:
159:            /**
160:             * return a table of the unprotected attributes indexed by
161:             * the OID of the attribute.
162:             */
163:            public AttributeTable getUnprotectedAttributes() {
164:                if (unprotectedAttributes == null) {
165:                    return null;
166:                }
167:
168:                return new AttributeTable(unprotectedAttributes);
169:            }
170:
171:            /**
172:             * return the ASN.1 encoded representation of this object.
173:             */
174:            public byte[] getEncoded() throws IOException {
175:                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
176:                ASN1OutputStream aOut = new ASN1OutputStream(bOut);
177:
178:                aOut.writeObject(contentInfo);
179:
180:                return bOut.toByteArray();
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.