public final class KeyUtil
extends java.lang.Object
| Constructor and Description |
|---|
KeyUtil() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
checkTlsPreMasterSecretKey(int clientVersion,
int serverVersion,
java.security.SecureRandom random,
byte[] encoded,
boolean isFailOver)
Check the format of TLS PreMasterSecret.
|
static java.lang.String |
fullDisplayAlgName(java.security.Key key)
Returns the algorithm name of the given key object.
|
static int |
getKeySize(java.security.AlgorithmParameters parameters)
Returns the key size of the given cryptographic parameters in bits.
|
static int |
getKeySize(java.security.Key key)
Returns the key size of the given key object in bits.
|
static boolean |
isOracleJCEProvider(java.lang.String providerName)
Returns whether the specified provider is Oracle provider or not.
|
static byte[] |
trimZeroes(byte[] b)
Trim leading (most significant) zeroes from the result.
|
static void |
validate(java.security.Key key)
Returns whether the key is valid or not.
|
static void |
validate(java.security.spec.KeySpec keySpec)
Returns whether the key spec is valid or not.
|
public static int getKeySize(java.security.Key key)
key - the key object, cannot be nullpublic static final int getKeySize(java.security.AlgorithmParameters parameters)
parameters - the cryptographic parameters, cannot be nullpublic static final java.lang.String fullDisplayAlgName(java.security.Key key)
key - the key object, cannot be nullpublic static final void validate(java.security.Key key)
throws java.security.InvalidKeyException
Note that this method is only apply to DHPublicKey at present.
key - the key object, cannot be nulljava.lang.NullPointerException - if key is nulljava.security.InvalidKeyException - if key is invalidpublic static final void validate(java.security.spec.KeySpec keySpec)
throws java.security.InvalidKeyException
Note that this method is only apply to DHPublicKeySpec at present.
keySpec - the key spec object, cannot be nulljava.lang.NullPointerException - if keySpec is nulljava.security.InvalidKeyException - if keySpec is invalidpublic static final boolean isOracleJCEProvider(java.lang.String providerName)
providerName - the provider nameproviderName is Oracle providerpublic static byte[] checkTlsPreMasterSecretKey(int clientVersion,
int serverVersion,
java.security.SecureRandom random,
byte[] encoded,
boolean isFailOver)
To avoid vulnerabilities described by section 7.4.7.1, RFC 5246, treating incorrectly formatted message blocks and/or mismatched version numbers in a manner indistinguishable from correctly formatted RSA blocks. RFC 5246 describes the approach as:
1. Generate a string R of 48 random bytes
2. Decrypt the message to recover the plaintext M
3. If the PKCS#1 padding is not correct, or the length of message
M is not exactly 48 bytes:
pre_master_secret = R
else If ClientHello.client_version <= TLS 1.0, and version
number check is explicitly disabled:
premaster secret = M
else If M[0..1] != ClientHello.client_version:
premaster secret = R
else:
premaster secret = M
Note that #2 should have completed before the call to this method.
clientVersion - the version of the TLS protocol by which the
client wishes to communicate during this sessionserverVersion - the negotiated version of the TLS protocol which
contains the lower of that suggested by the client in the client
hello and the highest supported by the server.encoded - the encoded key in its "RAW" encoding formatisFailOver - whether the previous decryption of the
encrypted PreMasterSecret message run into problempublic static byte[] trimZeroes(byte[] b)
java.lang.NullPointerException - if b is null