jdk/src/java.base/share/classes/java/security/AlgorithmParameterGenerator.java
author sherman
Tue, 10 May 2016 21:19:25 -0700
changeset 37882 e7f3cf12e739
parent 37348 9ccec3170d5e
child 41826 b35ee9b35b09
permissions -rw-r--r--
6328855: String: Matches hangs at short and easy Strings containing \r \n 6192895: java.util.regex.Matcher: Performance issue 6345469: java.util.regex.Matcher utilizes 100% of the CPU 6988218: RegEx matcher loops 6693451: RegEx matcher goes into infinite delay 7006761: Matcher.matches() has infinite loop 8140212: Slow performance of Matcher.find 8151481: j.u.regex.Pattern cleanup 6609854: Regex does not match correctly for negative nested character classes 4916384: CANON_EQ supports only combining character sequences with non-spacing marks 4867170: Pattern doesn't work with composite character in CANON_EQ mode 6995635: CANON_EQ pattern flag is buggy 6728861: ExceptionInInitializerError is caught when the pattern has precomposed character 6736245: A character in Composition Exclusion Table does not match itself 7080302: the normalization in java regex pattern may have flaw Reviewed-by: rriggs, okutsu, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
     2
 * Copyright (c) 1997, 2016, 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
/**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    31
 * The {@code AlgorithmParameterGenerator} class is used to generate a
2
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
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    34
 * are constructed using the {@code getInstance} factory methods
2
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
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    51
 * derived from the specified size.
2
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
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    64
 * (via a call to an {@code init} method), each provider must supply (and
2
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
 *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    69
 * <p> Every implementation of the Java platform is required to support the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    70
 * following standard {@code AlgorithmParameterGenerator} algorithms and
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    71
 * keysizes in parentheses:
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    72
 * <ul>
32647
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 25859
diff changeset
    73
 * <li>{@code DiffieHellman} (1024, 2048, 4096)</li>
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 25859
diff changeset
    74
 * <li>{@code DSA} (1024, 2048)</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    75
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    76
 * These algorithms are described in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    77
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    78
 * AlgorithmParameterGenerator section</a> of the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    79
 * Java Cryptography Architecture Standard Algorithm Name Documentation.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    80
 * Consult the release documentation for your implementation to see if any
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    81
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    82
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @see AlgorithmParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @see java.security.spec.AlgorithmParameterSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
public class AlgorithmParameterGenerator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // The provider implementation (delegate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private AlgorithmParameterGeneratorSpi paramGenSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // The algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private String 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
     * Creates an AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param paramGenSpi the delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param algorithm the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    protected AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    (AlgorithmParameterGeneratorSpi paramGenSpi, Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this.paramGenSpi = paramGenSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Returns the standard name of the algorithm this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * generator is associated with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return the string name of the algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * AlgorithmParameterGeneratorSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   141
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   142
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   143
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   144
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   145
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   146
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   147
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   148
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param algorithm the name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * parameter generator is associated with.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   151
     * See the AlgorithmParameterGenerator section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   152
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   153
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @return the new AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @exception NoSuchAlgorithmException if no Provider supports an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *          AlgorithmParameterGeneratorSpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static AlgorithmParameterGenerator getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                                 "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                                 (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    ((AlgorithmParameterGeneratorSpi)objs[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                     (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                     algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            } catch(NoSuchProviderException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                throw new NoSuchAlgorithmException(algorithm + " not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <p> A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * AlgorithmParameterGeneratorSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param algorithm the name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * parameter generator is associated with.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   193
     * See the AlgorithmParameterGenerator section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   194
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   195
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param provider the string name of the Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @return the new AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @exception NoSuchAlgorithmException if an AlgorithmParameterGeneratorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @exception IllegalArgumentException if the provider name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *          or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public static AlgorithmParameterGenerator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                                          String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        throws NoSuchAlgorithmException, NoSuchProviderException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (provider == null || provider.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                         "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                         provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
             algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <p> A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * AlgorithmParameterGeneratorSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param algorithm the string name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * parameter generator is associated with.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   239
     * See the AlgorithmParameterGenerator section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   240
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   241
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param provider the Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return the new AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @exception NoSuchAlgorithmException if an AlgorithmParameterGeneratorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @exception IllegalArgumentException if the specified provider is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public static AlgorithmParameterGenerator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                                          Provider provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        throws NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (provider == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                         "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                         provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
             algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Returns the provider of this algorithm parameter generator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the provider of this algorithm parameter generator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Initializes this parameter generator for a certain size.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   283
     * To create the parameters, the {@code SecureRandom}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * implementation of the highest-priority installed provider is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * (If none of the installed providers supply an implementation of
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   287
     * {@code SecureRandom}, a system-provided source of randomness is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param size the size (number of bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public final void init(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        paramGenSpi.engineInit(size, new SecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Initializes this parameter generator for a certain size and source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param size the size (number of bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param random the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public final void init(int size, SecureRandom random) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        paramGenSpi.engineInit(size, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Initializes this parameter generator with a set of algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * parameter generation values.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   310
     * To generate the parameters, the {@code SecureRandom}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * implementation of the highest-priority installed provider is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * (If none of the installed providers supply an implementation of
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   314
     * {@code SecureRandom}, a system-provided source of randomness is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param genParamSpec the set of algorithm-specific parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @exception InvalidAlgorithmParameterException if the given parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * generation values are inappropriate for this parameter generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public final void init(AlgorithmParameterSpec genParamSpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        throws InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            paramGenSpi.engineInit(genParamSpec, new SecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Initializes this parameter generator with a set of algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param genParamSpec the set of algorithm-specific parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param random the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @exception InvalidAlgorithmParameterException if the given parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * generation values are inappropriate for this parameter generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public final void init(AlgorithmParameterSpec genParamSpec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                           SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        throws InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            paramGenSpi.engineInit(genParamSpec, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Generates the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @return the new AlgorithmParameters object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public final AlgorithmParameters generateParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return paramGenSpi.engineGenerateParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}