public final class KeyUtil extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends Key> |
cloneKey(Class<T> expectType,
T key)
Attempt to create a safe clone of the given key object.
|
static AlgorithmParameterSpec |
getParameters(Key key)
Attempt to acquire parameters from the given key.
|
static <P extends AlgorithmParameterSpec> |
getParameters(Key key,
Class<P> paramSpecClass)
Attempt to acquire parameters of the given type from the given key.
|
static boolean |
hasParameters(Key key,
AlgorithmParameterSpec parameters)
Determine if the given key has parameters which match the given parameters.
|
static boolean |
hasSameParameters(Key key1,
Key key2)
Attempt to determine if the two keys have the same parameters.
|
static boolean |
parametersEqual(AlgorithmParameterSpec p1,
AlgorithmParameterSpec p2)
Attempt to determine if two algorithm parameter specifications are equal.
|
static int |
parametersHashCode(AlgorithmParameterSpec param)
Attempt to get a stable hash code for the given parameter specification.
|
public static AlgorithmParameterSpec getParameters(Key key)
key
- the key (must not be null
)null
if no known parameters are availablepublic static <P extends AlgorithmParameterSpec> P getParameters(Key key, Class<P> paramSpecClass)
P
- the parameter specification typekey
- the key (must not be null
)paramSpecClass
- the parameter specification class (must not be null
)null
if no known parameters of the given type are availablepublic static boolean hasParameters(Key key, AlgorithmParameterSpec parameters)
key
- the key (must not be null
)parameters
- the parameters (must not be null
)true
if the parameters match, false
otherwisepublic static boolean parametersEqual(AlgorithmParameterSpec p1, AlgorithmParameterSpec p2)
true
if the parameters are definitely the same, or false
if they are not definitely equal or equivalency cannot be determined.p1
- the first parameter specification (must not be null
)p2
- the second parameter specification (must not be null
)true
if the parameters are definitely equal, false
otherwisepublic static int parametersHashCode(AlgorithmParameterSpec param)
null
, a hash code of zero is returned.param
- the parameter specificationpublic static boolean hasSameParameters(Key key1, Key key2)
true
if the keys
definitely have the same parameters, or false
if they do not or if parameter equivalency cannot be determined.key1
- the first key (must not be null
)key2
- the second key (must not be null
)true
if the parameters are definitely equal, false
otherwisepublic static <T extends Key> T cloneKey(Class<T> expectType, T key)
Destroyable
; if not, it is returned as-is.
Next it checks to see if the key has been destroyed; if so, it is returned as-is.
Next it determines if the key actually implements the Destroyable
interface; if not, it is returned as-is.
Then it determines if there is a public clone
method that returns a compatible type; if so, that method is used.
Then it determines if the key implements a known key interface; if so, a raw implementation of that interface is produced.
Last it checks to see if the key is some other unknown SecretKey
type; if so, it captures its value using a SecretKeySpec
.
If none of these checks succeed, an exception is thrown.expectType
- the expected result type (must not be null
)key
- the key objectCopyright © 2020 JBoss by Red Hat. All rights reserved.