Source Code Cross Referenced for AES.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » 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 » 6.0 JDK Modules » j2me » com.sun.midp.crypto 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.crypto;
028:
029:        /**
030:         * Wrapper for all AES cipher classes.
031:         */
032:        public class AES extends Cipher {
033:            Cipher cipher;
034:
035:            /**
036:             * Public by name constructor.
037:             */
038:            public AES() {
039:            }
040:
041:            /**
042:             * Called by the factory method to set the mode and padding parameters.
043:             * Need because Class.newInstance does not take args.
044:             *
045:             * @param mode the mode parsed from the transformation parameter of
046:             *             getInstance
047:             * @param padding the paddinge parsed from the transformation parameter of
048:             *                getInstance
049:             *
050:             * @exception NoSuchPaddingException if <code>transformation</code>
051:             * contains a padding scheme that is not available.
052:             */
053:            protected void setChainingModeAndPadding(String mode, String padding)
054:                    throws NoSuchPaddingException {
055:                if (mode.equals("ECB") || mode.equals("")) {
056:                    cipher = new AES_ECB();
057:                } else if (mode.equals("CBC")) {
058:                    cipher = new AES_CBC();
059:                } else {
060:                    throw new IllegalArgumentException();
061:                }
062:
063:                cipher.setChainingModeAndPadding(mode, padding);
064:            }
065:
066:            /**
067:             * Initializes this cipher with a key and a set of algorithm
068:             * parameters.
069:             *
070:             * <p>The cipher is initialized for one of the following  operations:
071:             * encryption or decryption depending
072:             * on the value of <code>opmode</code>.
073:             *
074:             * <p>If this cipher requires any algorithm parameters and
075:             * <code>params</code> is null, the underlying cipher implementation is
076:             * supposed to generate the required parameters itself (using
077:             * provider-specific default or random values) if it is being
078:             * initialized for encryption, and raise an
079:             * <code>InvalidAlgorithmParameterException</code> if it is being
080:             * initialized for decryption.
081:             *
082:             * <p>Note that when a Cipher object is initialized, it loses all
083:             * previously-acquired state. In other words, initializing a Cipher is
084:             * equivalent to creating a new instance of that Cipher and initializing
085:             * it.
086:             *
087:             * @param opmode the operation mode of this cipher (this is one of the
088:             * following:
089:             * <code>ENCRYPT_MODE</code> or <code>DECRYPT_MODE</code>)
090:             * @param key the encryption key
091:             * @param params the algorithm parameters
092:             *
093:             * @exception InvalidKeyException if the given key is inappropriate for
094:             * initializing this cipher, or its keysize exceeds the maximum allowable
095:             * keysize.
096:             * @exception InvalidAlgorithmParameterException if the given algorithm
097:             * parameters are inappropriate for this cipher,
098:             * or this cipher is being initialized for decryption and requires
099:             * algorithm parameters and <code>params</code> is null, or the given
100:             * algorithm parameters imply a cryptographic strength that would exceed
101:             * the legal limits.
102:             */
103:            public void init(int opmode, Key key, CryptoParameter params)
104:                    throws InvalidKeyException,
105:                    InvalidAlgorithmParameterException {
106:                cipher.init(opmode, key, params);
107:            }
108:
109:            /**
110:             * Continues a multiple-part encryption or decryption operation
111:             * (depending on how this cipher was initialized), processing another data
112:             * part.
113:             *
114:             * <p>The first <code>inputLen</code> bytes in the <code>input</code>
115:             * buffer, starting at <code>inputOffset</code> inclusive, are processed,
116:             * and the result is stored in the <code>output</code> buffer, starting at
117:             * <code>outputOffset</code> inclusive.
118:             *
119:             * <p>If the <code>output</code> buffer is too small to hold the result,
120:             * a <code>ShortBufferException</code> is thrown. In this case, repeat this
121:             * call with a larger output buffer.
122:             *
123:             * <p>If <code>inputLen</code> is zero, this method returns
124:             * a length of zero.
125:             *
126:             * <p>Note: this method should be copy-safe, which means the
127:             * <code>input</code> and <code>output</code> buffers can reference
128:             * the same byte array and no unprocessed input data is overwritten
129:             * when the result is copied into the output buffer.
130:             *
131:             * @param input the input buffer
132:             * @param inputOffset the offset in <code>input</code> where the input
133:             * starts
134:             * @param inputLen the input length
135:             * @param output the buffer for the result
136:             * @param outputOffset the offset in <code>output</code> where the result
137:             * is stored
138:             *
139:             * @return the number of bytes stored in <code>output</code>
140:             *
141:             * @exception IllegalStateException if this cipher is in a wrong state
142:             * (e.g., has not been initialized)
143:             * @exception ShortBufferException if the given output buffer is too small
144:             * to hold the result
145:             */
146:            public int update(byte[] input, int inputOffset, int inputLen,
147:                    byte[] output, int outputOffset)
148:                    throws IllegalStateException, ShortBufferException {
149:                return cipher.update(input, inputOffset, inputLen, output,
150:                        outputOffset);
151:            }
152:
153:            /**
154:             * Encrypts or decrypts data in a single-part operation, or finishes a
155:             * multiple-part operation. The data is encrypted or decrypted,
156:             * depending on how this cipher was initialized.
157:             *
158:             * <p>The first <code>inputLen</code> bytes in the <code>input</code>
159:             * buffer, starting at <code>inputOffset</code> inclusive, and any input
160:             * bytes that may have been buffered during a previous
161:             * <code>update</code> operation, are processed, with padding
162:             * (if requested) being applied.
163:             * The result is stored in the <code>output</code> buffer, starting at
164:             * <code>outputOffset</code> inclusive.
165:             *
166:             * <p>If the <code>output</code> buffer is too small to hold the result,
167:             * a <code>ShortBufferException</code> is thrown. In this case, repeat this
168:             * call with a larger output buffer.
169:             *
170:             * <p>Upon finishing, this method resets this cipher object to the state
171:             * it was in when previously initialized via a call to <code>init</code>.
172:             * That is, the object is reset and available to encrypt or decrypt
173:             * (depending on the operation mode that was specified in the call to
174:             * <code>init</code>) more data.
175:             *
176:             * <p>Note: if any exception is thrown, this cipher object may need to
177:             * be reset before it can be used again.
178:             *
179:             * <p>Note: this method should be copy-safe, which means the
180:             * <code>input</code> and <code>output</code> buffers can reference
181:             * the same byte array and no unprocessed input data is overwritten
182:             * when the result is copied into the output buffer.
183:             *
184:             * @param input the input buffer
185:             * @param inputOffset the offset in <code>input</code> where the input
186:             * starts
187:             * @param inputLen the input length
188:             * @param output the buffer for the result
189:             * @param outputOffset the offset in <code>output</code> where the result
190:             * is stored
191:             *
192:             * @return the number of bytes stored in <code>output</code>
193:             *
194:             * @exception IllegalStateException if this cipher is in a wrong state
195:             * (e.g., has not been initialized)
196:             * @exception IllegalBlockSizeException if this cipher is a block cipher,
197:             * no padding has been requested (only in encryption mode), and the total
198:             * input length of the data processed by this cipher is not a multiple of
199:             * block size
200:             * @exception ShortBufferException if the given output buffer is too small
201:             * to hold the result
202:             * @exception BadPaddingException if this cipher is in decryption mode,
203:             * and (un)padding has been requested, but the decrypted data is not
204:             * bounded by the appropriate padding bytes
205:             */
206:            public int doFinal(byte[] input, int inputOffset, int inputLen,
207:                    byte[] output, int outputOffset)
208:                    throws IllegalStateException, ShortBufferException,
209:                    IllegalBlockSizeException, BadPaddingException {
210:                return cipher.doFinal(input, inputOffset, inputLen, output,
211:                        outputOffset);
212:            }
213:
214:            /**
215:             * Returns the initialization vector (IV) in a new buffer.
216:             * This is useful in the case where a random IV was created.
217:             * @return the initialization vector in a new buffer,
218:             * or <code>null</code> if the underlying algorithm does
219:             * not use an IV, or if the IV has not yet been set.
220:             */
221:            public byte[] getIV() {
222:                return cipher.getIV();
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.