jdk/src/share/classes/java/security/AlgorithmParameterGenerator.java
author never
Mon, 12 Jul 2010 22:27:18 -0700
changeset 5926 a36f90d986b6
parent 5506 202f599c92aa
child 8152 94e5966bdf22
permissions -rw-r--r--
6968385: malformed xml in sweeper logging Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The <code>AlgorithmParameterGenerator</code> class is used to generate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * parameters to be used with a certain algorithm. Parameter generators
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * are constructed using the <code>getInstance</code> factory methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * (static methods that return instances of a given class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>The object that will generate the parameters can be initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * in two different ways: in an algorithm-independent manner, or in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * algorithm-specific manner:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <li>The algorithm-independent approach uses the fact that all parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * generators share the concept of a "size" and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * source of randomness. The measure of size is universally shared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * by all algorithm parameters, though it is interpreted differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * for different algorithms. For example, in the case of parameters for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the <i>DSA</i> algorithm, "size" corresponds to the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * of the prime modulus (in bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * When using this approach, algorithm-specific parameter generation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * values - if any - default to some standard values, unless they can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * derived from the specified size.<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <li>The other approach initializes a parameter generator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * using algorithm-specific semantics, which are represented by a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * algorithm-specific parameter generation values. To generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Diffie-Hellman system parameters, for example, the parameter generation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * values usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * consist of the size of the prime modulus and the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * random exponent, both specified in number of bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <P>In case the client does not explicitly initialize the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * (via a call to an <code>init</code> method), each provider must supply (and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * document) a default initialization. For example, the Sun provider uses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * default modulus prime size of 1024 bits for the generation of DSA
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @see AlgorithmParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see java.security.spec.AlgorithmParameterSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
public class AlgorithmParameterGenerator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // The provider implementation (delegate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private AlgorithmParameterGeneratorSpi paramGenSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // The algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Creates an AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param paramGenSpi the delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param algorithm the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    (AlgorithmParameterGeneratorSpi paramGenSpi, Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.paramGenSpi = paramGenSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Returns the standard name of the algorithm this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * generator is associated with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @return the string name of the algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * AlgorithmParameterGeneratorSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param algorithm the name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * parameter generator is associated with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the new AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @exception NoSuchAlgorithmException if no Provider supports an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *          AlgorithmParameterGeneratorSpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public static AlgorithmParameterGenerator getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                                 "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                                 (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    ((AlgorithmParameterGeneratorSpi)objs[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                     (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                     algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            } catch(NoSuchProviderException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                throw new NoSuchAlgorithmException(algorithm + " not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p> A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * AlgorithmParameterGeneratorSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param algorithm the name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * parameter generator is associated with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param provider the string name of the Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return the new AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @exception NoSuchAlgorithmException if an AlgorithmParameterGeneratorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @exception IllegalArgumentException if the provider name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *          or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public static AlgorithmParameterGenerator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                                          String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        throws NoSuchAlgorithmException, NoSuchProviderException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (provider == null || provider.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                         "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                         provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
             algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <p> A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * AlgorithmParameterGeneratorSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param algorithm the string name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * parameter generator is associated with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param provider the Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return the new AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @exception NoSuchAlgorithmException if an AlgorithmParameterGeneratorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @exception IllegalArgumentException if the specified provider is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static AlgorithmParameterGenerator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                          Provider provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        throws NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (provider == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                         "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                         provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
             algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Returns the provider of this algorithm parameter generator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @return the provider of this algorithm parameter generator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Initializes this parameter generator for a certain size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * To create the parameters, the <code>SecureRandom</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * implementation of the highest-priority installed provider is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * (If none of the installed providers supply an implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * <code>SecureRandom</code>, a system-provided source of randomness is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param size the size (number of bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public final void init(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        paramGenSpi.engineInit(size, new SecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Initializes this parameter generator for a certain size and source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param size the size (number of bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param random the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public final void init(int size, SecureRandom random) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        paramGenSpi.engineInit(size, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Initializes this parameter generator with a set of algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * To generate the parameters, the <code>SecureRandom</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * implementation of the highest-priority installed provider is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * (If none of the installed providers supply an implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <code>SecureRandom</code>, a system-provided source of randomness is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param genParamSpec the set of algorithm-specific parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @exception InvalidAlgorithmParameterException if the given parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * generation values are inappropriate for this parameter generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public final void init(AlgorithmParameterSpec genParamSpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        throws InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            paramGenSpi.engineInit(genParamSpec, new SecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Initializes this parameter generator with a set of algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @param genParamSpec the set of algorithm-specific parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @param random the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @exception InvalidAlgorithmParameterException if the given parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * generation values are inappropriate for this parameter generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public final void init(AlgorithmParameterSpec genParamSpec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                           SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        throws InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            paramGenSpi.engineInit(genParamSpec, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Generates the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @return the new AlgorithmParameters object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public final AlgorithmParameters generateParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return paramGenSpi.engineGenerateParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}