Source Code Cross Referenced for AsymmetricEncryption.java in  » Web-Mail » oyster » org » enhydra » oyster » crypto » 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 » Web Mail » oyster » org.enhydra.oyster.crypto 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Title:        Oyster Project
003:         * Description:  S/MIME email sending capabilities
004:         * @Author       Vladan Obradovic, Vladimir Radisic
005:         * @Version      2.1.6
006:         */
007:
008:        package org.enhydra.oyster.crypto;
009:
010:        import java.security.Key;
011:        import javax.crypto.Cipher;
012:        import org.enhydra.oyster.exception.SMIMEException;
013:        import org.enhydra.oyster.exception.ErrorStorage;
014:
015:        /**
016:         * AsymmetricEncryption class is used for asymmetric encryption of the small
017:         * parts of data (for exsample to encrypt symmetric key genereted in the class
018:         * SymmetricEncryption). Performed algorithm is RSA/ECB/PKCS1Padding.<BR>
019:         *<BR>
020:         * In order to create a Cipher object, the application calls the Cipher's
021:         * getInstance method, and passes the name of the requested transformation to it.
022:         * The name of a provider may be specified.
023:         */
024:        public class AsymmetricEncryption {
025:
026:            /**
027:             * Container for encrypted value.
028:             */
029:            private byte[] encryptContent = null;
030:
031:            /**
032:             * Container for decrypted value.
033:             */
034:            private byte[] decryptContent = null;
035:
036:            /**
037:             * Default constructor
038:             */
039:            public AsymmetricEncryption() {
040:            }
041:
042:            /**
043:             * Perform RSA encryption of the input byte array with the private or public key.
044:             * @param key0 private or public key
045:             * @param forEncrypt0 content for encryption
046:             * @exception SMIMEException caused by non SMIMEException which can be one of
047:             * the following: NoSuchPaddingException, NoSuchProviderException,
048:             * NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
049:             * IllegalBlockSizeException.
050:             */
051:            public void encrypt(Key key0, byte[] forEncrypt0)
052:                    throws SMIMEException {
053:                try {
054:                    Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
055:                    c.init(Cipher.ENCRYPT_MODE, key0);
056:                    encryptContent = c.doFinal(forEncrypt0);
057:                } catch (Exception e) {
058:                    throw new SMIMEException(e);
059:                }
060:            }
061:
062:            /**
063:             * Returns encrypted value. To work properly encryption must be first performed.
064:             * @return Encrypted value represented as byte array.
065:             */
066:            public byte[] getEncryptedValue() {
067:                return encryptContent;
068:            }
069:
070:            /**
071:             * Perform RSA decryption of the input byte array with the public or private key.
072:             * @param key0 private or public key
073:             * @param forDecrypt0 content for decryption
074:             * @exception SMIMEException caused by non SMIMEException which can be one of the following:
075:             * NoSuchPaddingException, NoSuchProviderException, NoSuchAlgorithmException,
076:             * InvalidKeyException, BadPaddingException, IllegalBlockSizeException.
077:             */
078:            public void decrypt(Key key0, byte[] forDecrypt0)
079:                    throws SMIMEException {
080:                try {
081:                    Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
082:                    c.init(Cipher.DECRYPT_MODE, key0);
083:                    decryptContent = c.doFinal(forDecrypt0);
084:                } catch (Exception e) {
085:                    throw new SMIMEException(e);
086:                }
087:            }
088:
089:            /**
090:             * Returns the decrypted value. To work properly, decryption must be first
091:             * performed.
092:             * @return Decrypted value represented as byte array.
093:             */
094:            public byte[] getDecryptedValue() {
095:                return decryptContent;
096:            }
097:
098:            /**
099:             * Resets (sets to null) all private attributes in the generated instance
100:             * of the class.
101:             */
102:            void reset() {
103:                encryptContent = null;
104:                decryptContent = null;
105:            }
106:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.