Source Code Cross Referenced for RsaMd5Sig.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:         * Implements RSA MD5 Signatures.
031:         */
032:        public final class RsaMd5Sig extends Signature {
033:            /**
034:             * Expected prefix in the decrypted result when MD5 hashing is used
035:             * with RSA signing. This prefix is followed by the MD5 hash.
036:             * If you are interested, more details are in the comments around 
037:             * the verify method in X509Certificate.
038:             */
039:            private static final byte[] PREFIX_MD5 = { (byte) 0x30,
040:                    (byte) 0x20, (byte) 0x30, (byte) 0x0c, (byte) 0x06,
041:                    (byte) 0x08, (byte) 0x2a, (byte) 0x86, (byte) 0x48,
042:                    (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x02,
043:                    (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x04,
044:                    (byte) 0x10 };
045:
046:            /** Common signature class. */
047:            RSASig rsaSig;
048:
049:            /**
050:             * Constructs an RSA signature object that uses MD5 as 
051:             * message digest algorithm.
052:             *
053:             * @exception RuntimeException if MD5 is not available
054:             */
055:            public RsaMd5Sig() {
056:                try {
057:                    rsaSig = new RSASig(PREFIX_MD5, MessageDigest
058:                            .getInstance("MD5"));
059:                } catch (NoSuchAlgorithmException e) {
060:                    throw new RuntimeException("Needed algorithm not available");
061:                }
062:            }
063:
064:            /**
065:             * Gets the signature algorithm.
066:             *
067:             * @return the algorithmimplemented by this signature object
068:             */
069:            public String getAlgorithm() {
070:                return "MD5withRSA";
071:            }
072:
073:            /**
074:             * Gets the byte-length of the signature.
075:             * 
076:             * @return the byte-length of the signature produced by this object
077:             */
078:            public int getLength() {
079:                return rsaSig.getLength();
080:            }
081:
082:            /**
083:             * Initializes the <CODE>RSASig</CODE> object with the appropriate
084:             * <CODE>Key</CODE> for signature verification.
085:             * 
086:             * @param theKey the key object to use for verification
087:             *
088:             * @exception InvalidKeyException if the key type is inconsistent 
089:             * with the mode or signature implementation.
090:             */
091:            public void initVerify(PublicKey theKey) throws InvalidKeyException {
092:                rsaSig.initVerify(theKey);
093:            }
094:
095:            /**
096:             * Initializes the <CODE>RSASig</CODE> object with the appropriate
097:             * <CODE>Key</CODE> for signature creation.
098:             * 
099:             * @param theKey the key object to use for signing
100:             *
101:             * @exception InvalidKeyException if the key type is inconsistent 
102:             * with the mode or signature implementation.
103:             */
104:            public void initSign(PrivateKey theKey) throws InvalidKeyException {
105:                rsaSig.initSign(theKey);
106:            }
107:
108:            /**
109:             * Accumulates a signature of the input data. When this method is used,
110:             * temporary storage of intermediate results is required. This method
111:             * should only be used if all the input data required for the signature
112:             * is not available in one byte array. The sign() or verify() method is 
113:             * recommended whenever possible. 
114:             *
115:             * @param inBuf the input buffer of data to be signed
116:             * @param inOff starting offset within the input buffer for data to
117:             *              be signed
118:             * @param inLen the byte length of data to be signed
119:             *
120:             * @exception SignatureException
121:             * if the signature algorithm does not pad the message and the
122:             * message is not block aligned
123:             *
124:             * @see #verify(byte[], int, int, byte[], int, short)
125:             */
126:            public void update(byte[] inBuf, int inOff, int inLen)
127:                    throws SignatureException {
128:
129:                rsaSig.update(inBuf, inOff, inLen);
130:            }
131:
132:            /**
133:             * Generates the signature of all/last input data. A call to this
134:             * method also resets this signature object to the state it was in
135:             * when previously initialized via a call to init(). That is, the
136:             * object is reset and available to sign another message.
137:             * 
138:             * @param sigBuf the output buffer to store signature data
139:             * @param sigOff starting offset within the output buffer at which
140:             *               to begin signature data
141:             * @param sigLen max length the signature can be
142:             *
143:             * @return number of bytes of signature output in sigBuf
144:             *
145:             * @exception SignatureException 
146:             * if the signature algorithm does not pad the message and the
147:             * message is not block aligned
148:             */
149:            public int sign(byte[] sigBuf, int sigOff, int sigLen)
150:                    throws SignatureException {
151:
152:                return rsaSig.sign(sigBuf, sigOff, sigLen);
153:            }
154:
155:            /**
156:             * Verifies the signature of all/last input data against the passed
157:             * in signature. A call to this method also resets this signature 
158:             * object to the state it was in when previously initialized via a
159:             * call to init(). That is, the object is reset and available to 
160:             * verify another message.
161:             * 
162:             * @param sigBuf the input buffer containing signature data
163:             * @param sigOff starting offset within the sigBuf where signature
164:             *               data begins
165:             * @param sigLen byte length of signature data
166:             *
167:             * @return true if signature verifies, false otherwise
168:             *
169:             * @exception SignatureException 
170:             * if the signature algorithm does not pad the message and the
171:             * message is not block aligned
172:             */
173:            public boolean verify(byte[] sigBuf, int sigOff, int sigLen)
174:                    throws SignatureException {
175:
176:                return rsaSig.verify(sigBuf, sigOff, sigLen);
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.