Source Code Cross Referenced for PSSParameterSpec.java in  » 6.0-JDK-Core » security » java » security » spec » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » security » java.security.spec 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2001-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.security.spec;
027
028        import java.math.BigInteger;
029        import java.security.spec.MGF1ParameterSpec;
030
031        /**
032         * This class specifies a parameter spec for RSA-PSS signature scheme,
033         * as defined in the 
034         * <a href="http://www.ietf.org/rfc/rfc3447.txt">PKCS#1 v2.1</a>
035         * standard.
036         *
037         * <p>Its ASN.1 definition in PKCS#1 standard is described below:
038         * <pre>
039         * RSASSA-PSS-params ::= SEQUENCE {
040         *   hashAlgorithm      [0] OAEP-PSSDigestAlgorithms  DEFAULT sha1,
041         *   maskGenAlgorithm   [1] PKCS1MGFAlgorithms  DEFAULT mgf1SHA1,
042         *   saltLength         [2] INTEGER  DEFAULT 20,
043         *   trailerField       [3] INTEGER  DEFAULT 1
044         * }
045         * </pre>
046         * where
047         * <pre>
048         * OAEP-PSSDigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
049         *   { OID id-sha1 PARAMETERS NULL   }|
050         *   { OID id-sha256 PARAMETERS NULL }|
051         *   { OID id-sha384 PARAMETERS NULL }|
052         *   { OID id-sha512 PARAMETERS NULL },
053         *   ...  -- Allows for future expansion --
054         * }
055         *
056         * PKCS1MGFAlgorithms    ALGORITHM-IDENTIFIER ::= {
057         *   { OID id-mgf1 PARAMETERS OAEP-PSSDigestAlgorithms },
058         *   ...  -- Allows for future expansion --
059         * }
060         * </pre>
061         * <p>Note: the PSSParameterSpec.DEFAULT uses the following:
062         *     message digest  -- "SHA-1"
063         *     mask generation function (mgf) -- "MGF1"
064         *     parameters for mgf -- MGF1ParameterSpec.SHA1
065         *     SaltLength   -- 20
066         *     TrailerField -- 1
067         *
068         * @see MGF1ParameterSpec
069         * @see AlgorithmParameterSpec
070         * @see java.security.Signature
071         *
072         * @author Valerie Peng
073         *
074         * @version 1.15 07/05/05
075         *
076         * @since 1.4
077         */
078
079        public class PSSParameterSpec implements  AlgorithmParameterSpec {
080
081            private String mdName = "SHA-1";
082            private String mgfName = "MGF1";
083            private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
084            private int saltLen = 20;
085            private int trailerField = 1;
086
087            /**
088             * The PSS parameter set with all default values.
089             * @since 1.5
090             */
091            public static final PSSParameterSpec DEFAULT = new PSSParameterSpec();
092
093            /**
094             * Constructs a new <code>PSSParameterSpec</code> as defined in
095             * the PKCS #1 standard using the default values.
096             */
097            private PSSParameterSpec() {
098            }
099
100            /**
101             * Creates a new <code>PSSParameterSpec</code> as defined in
102             * the PKCS #1 standard using the specified message digest,
103             * mask generation function, parameters for mask generation 
104             * function, salt length, and trailer field values.
105             *
106             * @param mdName the algorithm name of the hash function.
107             * @param mgfName the algorithm name of the mask generation 
108             * function.
109             * @param mgfSpec the parameters for the mask generation 
110             * function. If null is specified, null will be returned by 
111             * getMGFParameters().
112             * @param saltLen the length of salt.
113             * @param trailerField the value of the trailer field.
114             * @exception NullPointerException if <code>mdName</code>, 
115             * or <code>mgfName</code> is null.
116             * @exception IllegalArgumentException if <code>saltLen</code>
117             * or <code>trailerField</code> is less than 0.
118             * @since 1.5
119             */
120            public PSSParameterSpec(String mdName, String mgfName,
121                    AlgorithmParameterSpec mgfSpec, int saltLen,
122                    int trailerField) {
123                if (mdName == null) {
124                    throw new NullPointerException("digest algorithm is null");
125                }
126                if (mgfName == null) {
127                    throw new NullPointerException("mask generation function "
128                            + "algorithm is null");
129                }
130                if (saltLen < 0) {
131                    throw new IllegalArgumentException(
132                            "negative saltLen value: " + saltLen);
133                }
134                if (trailerField < 0) {
135                    throw new IllegalArgumentException(
136                            "negative trailerField: " + trailerField);
137                }
138                this .mdName = mdName;
139                this .mgfName = mgfName;
140                this .mgfSpec = mgfSpec;
141                this .saltLen = saltLen;
142                this .trailerField = trailerField;
143            }
144
145            /**
146             * Creates a new <code>PSSParameterSpec</code>
147             * using the specified salt length and other default values as 
148             * defined in PKCS#1.
149             *
150             * @param saltLen the length of salt in bits to be used in PKCS#1 
151             * PSS encoding.
152             * @exception IllegalArgumentException if <code>saltLen</code> is
153             * less than 0.
154             */
155            public PSSParameterSpec(int saltLen) {
156                if (saltLen < 0) {
157                    throw new IllegalArgumentException(
158                            "negative saltLen value: " + saltLen);
159                }
160                this .saltLen = saltLen;
161            }
162
163            /**
164             * Returns the message digest algorithm name.
165             *
166             * @return the message digest algorithm name.
167             * @since 1.5
168             */
169            public String getDigestAlgorithm() {
170                return mdName;
171            }
172
173            /**
174             * Returns the mask generation function algorithm name.
175             *
176             * @return the mask generation function algorithm name.
177             *
178             * @since 1.5
179             */
180            public String getMGFAlgorithm() {
181                return mgfName;
182            }
183
184            /**
185             * Returns the parameters for the mask generation function.
186             *
187             * @return the parameters for the mask generation function.
188             * @since 1.5
189             */
190            public AlgorithmParameterSpec getMGFParameters() {
191                return mgfSpec;
192            }
193
194            /**
195             * Returns the salt length in bits.
196             *
197             * @return the salt length.
198             */
199            public int getSaltLength() {
200                return saltLen;
201            }
202
203            /**
204             * Returns the value for the trailer field, i.e. bc in PKCS#1 v2.1.
205             *
206             * @return the value for the trailer field, i.e. bc in PKCS#1 v2.1.
207             * @since 1.5
208             */
209            public int getTrailerField() {
210                return trailerField;
211            }
212        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.