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