Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/javax/crypto/KeyGeneratorSpi.java
41152 views
1
/*
2
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package javax.crypto;
27
28
import java.security.*;
29
import java.security.spec.*;
30
31
/**
32
* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
33
* for the <code>KeyGenerator</code> class.
34
* All the abstract methods in this class must be implemented by each
35
* cryptographic service provider who wishes to supply the implementation
36
* of a key generator for a particular algorithm.
37
*
38
* <p>In case the client does not explicitly initialize the KeyGenerator
39
* (via a call to an {@code init} method), each provider must
40
* supply (and document) a default initialization.
41
* See the Keysize Restriction sections of the
42
* {@extLink security_guide_jdk_providers JDK Providers}
43
* document for information on the KeyGenerator defaults used by
44
* JDK providers.
45
* However, note that defaults may vary across different providers.
46
* Additionally, the default value for a provider may change in a future
47
* version. Therefore, it is recommended to explicitly initialize the
48
* KeyGenerator instead of relying on provider-specific defaults.
49
*
50
* @author Jan Luehe
51
*
52
* @see SecretKey
53
* @since 1.4
54
*/
55
56
public abstract class KeyGeneratorSpi {
57
58
/**
59
* Constructor for subclasses to call.
60
*/
61
public KeyGeneratorSpi() {}
62
63
/**
64
* Initializes the key generator.
65
*
66
* @param random the source of randomness for this generator
67
*/
68
protected abstract void engineInit(SecureRandom random);
69
70
/**
71
* Initializes the key generator with the specified parameter
72
* set and a user-provided source of randomness.
73
*
74
* @param params the key generation parameters
75
* @param random the source of randomness for this key generator
76
*
77
* @exception InvalidAlgorithmParameterException if <code>params</code> is
78
* inappropriate for this key generator
79
*/
80
protected abstract void engineInit(AlgorithmParameterSpec params,
81
SecureRandom random)
82
throws InvalidAlgorithmParameterException;
83
84
/**
85
* Initializes this key generator for a certain keysize, using the given
86
* source of randomness.
87
*
88
* @param keysize the keysize. This is an algorithm-specific metric,
89
* specified in number of bits.
90
* @param random the source of randomness for this key generator
91
*
92
* @exception InvalidParameterException if the keysize is wrong or not
93
* supported.
94
*/
95
protected abstract void engineInit(int keysize, SecureRandom random);
96
97
/**
98
* Generates a secret key.
99
*
100
* @return the new key
101
*/
102
protected abstract SecretKey engineGenerateKey();
103
}
104
105