Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/javax/crypto/SecretKeyFactorySpi.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>SecretKeyFactory</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 secret-key factory for a particular algorithm.
37
*
38
* <P> A provider should document all the key specifications supported by its
39
* secret key factory.
40
* For example, the DES secret-key factory supplied by the "SunJCE" provider
41
* supports <code>DESKeySpec</code> as a transparent representation of DES
42
* keys, and that provider's secret-key factory for Triple DES keys supports
43
* <code>DESedeKeySpec</code> as a transparent representation of Triple DES
44
* keys.
45
*
46
* @author Jan Luehe
47
*
48
* @see SecretKey
49
* @see javax.crypto.spec.DESKeySpec
50
* @see javax.crypto.spec.DESedeKeySpec
51
* @since 1.4
52
*/
53
54
public abstract class SecretKeyFactorySpi {
55
56
/**
57
* Constructor for subclasses to call.
58
*/
59
public SecretKeyFactorySpi() {}
60
61
/**
62
* Generates a <code>SecretKey</code> object from the
63
* provided key specification (key material).
64
*
65
* @param keySpec the specification (key material) of the secret key
66
*
67
* @return the secret key
68
*
69
* @exception InvalidKeySpecException if the given key specification
70
* is inappropriate for this secret-key factory to produce a secret key.
71
*/
72
protected abstract SecretKey engineGenerateSecret(KeySpec keySpec)
73
throws InvalidKeySpecException;
74
75
/**
76
* Returns a specification (key material) of the given key
77
* object in the requested format.
78
*
79
* @param key the key
80
*
81
* @param keySpec the requested format in which the key material shall be
82
* returned
83
*
84
* @return the underlying key specification (key material) in the
85
* requested format
86
*
87
* @exception InvalidKeySpecException if the requested key specification is
88
* inappropriate for the given key (e.g., the algorithms associated with
89
* <code>key</code> and <code>keySpec</code> do not match, or
90
* <code>key</code> references a key on a cryptographic hardware device
91
* whereas <code>keySpec</code> is the specification of a software-based
92
* key), or the given key cannot be dealt with
93
* (e.g., the given key has an algorithm or format not supported by this
94
* secret-key factory).
95
*/
96
protected abstract KeySpec engineGetKeySpec(SecretKey key, Class<?> keySpec)
97
throws InvalidKeySpecException;
98
99
/**
100
* Translates a key object, whose provider may be unknown or
101
* potentially untrusted, into a corresponding key object of this
102
* secret-key factory.
103
*
104
* @param key the key whose provider is unknown or untrusted
105
*
106
* @return the translated key
107
*
108
* @exception InvalidKeyException if the given key cannot be processed
109
* by this secret-key factory.
110
*/
111
protected abstract SecretKey engineTranslateKey(SecretKey key)
112
throws InvalidKeyException;
113
}
114
115