public final class KeyUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static Factory<Digest> |
DEFAULT_FINGERPRINT_DIGEST_FACTORY
|
static Set<PosixFilePermission> |
STRICTLY_PROHIBITED_FILE_PERMISSION
The
Set of PosixFilePermission not allowed if strict
permissions are enforced on key files |
public static final Set<PosixFilePermission> STRICTLY_PROHIBITED_FILE_PERMISSION
Set of PosixFilePermission not allowed if strict
permissions are enforced on key filespublic static PosixFilePermission validateStrictKeyFilePermissions(Path path, LinkOption... options) throws IOException
Checks if a path has strict permissions
The path may not have PosixFilePermission.OTHERS_EXECUTE
permission
(For Unix) The path may not have group or others permissions
(For Unix) If the path is a file, then its folder may not have
group or others permissions
path - The Path to be checked - ignored if null
or does not existoptions - The LinkOptions to use to query the file's permissionsPosixFilePermission - null if
no violations detectedIOException - If failed to retrieve the permissionsSTRICTLY_PROHIBITED_FILE_PERMISSIONpublic static KeyPair generateKeyPair(String keyType, int keySize) throws GeneralSecurityException
keyType - The key type - OpenSSH name - e.g., ssh-rsa, ssh-dsskeySize - The key size (in bits)KeyPair of the specified type and sizeGeneralSecurityException - If failed to generate the key pairgetPublicKeyEntryDecoder(String),
PublicKeyEntryDecoder.generateKeyPair(int)public static KeyPair cloneKeyPair(String keyType, KeyPair kp) throws GeneralSecurityException
KeyPair - i.e., creates
new public/private keys that are clones of the original onekeyType - The key type - OpenSSH name - e.g., ssh-rsa, ssh-dsskp - The KeyPair to clone - ignored if nullGeneralSecurityException - If failed to clone the pairpublic static void registerPublicKeyEntryDecoder(PublicKeyEntryDecoder<?,?> decoder)
decoder - The decoder to registerIllegalArgumentException - if no decoder or not key type or no
supported names for the decoderPublicKeyEntryDecoder.getPublicKeyType(),
PublicKeyEntryDecoder.getSupportedTypeNames()public static PublicKeyEntryDecoder<?,?> getPublicKeyEntryDecoder(String keyType)
keyType - The OpenSSH key type string - e.g., ssh-rsa, ssh-dss
- ignored if null/emptyPublicKeyEntryDecoder or {code null} if not foundpublic static PublicKeyEntryDecoder<?,?> getPublicKeyEntryDecoder(KeyPair kp)
kp - The KeyPair to examine - ignored if nullPublicKeyEntryDecoder provided both
the public and private keys have the same decoder - null if no
match foundgetPublicKeyEntryDecoder(Key)public static PublicKeyEntryDecoder<?,?> getPublicKeyEntryDecoder(Key key)
key - The Key (public or private) - ignored if nullPublicKeyEntryDecoder for this key or {code null} if no match foundgetPublicKeyEntryDecoder(Class)public static PublicKeyEntryDecoder<?,?> getPublicKeyEntryDecoder(Class<?> keyType)
keyType - The key Class - ignored if null or not a Key
compatible typePublicKeyEntryDecoder or {code null} if no match foundpublic static Factory<? extends Digest> getDefaultFingerPrintFactory()
Factory of Digests used
by the getFingerPrint(PublicKey) and getFingerPrint(String)
methodssetDefaultFingerPrintFactory(Factory)public static void setDefaultFingerPrintFactory(Factory<? extends Digest> f)
public static String getFingerPrint(PublicKey key)
key - the public key - ignored if nullnull if no key.
Note: if exception encountered then returns the exception's simple class namegetFingerPrint(Factory, PublicKey)public static String getFingerPrint(String password)
password - The String to digest - ignored if null/empty,
otherwise its UTF-8 representation is used as input for the fingerprintnull if null/empty input.
Note: if exception encountered then returns the exception's simple class namegetFingerPrint(String, Charset)public static String getFingerPrint(String password, Charset charset)
password - The String to digest - ignored if null/emptycharset - The Charset to use in order to convert the
string to its byte representation to use as input for the fingerprintnull if null/empty input.
Note: if exception encountered then returns the exception's simple class namegetFingerPrint(Factory, String, Charset),
getDefaultFingerPrintFactory()public static String getFingerPrint(Factory<? extends Digest> f, PublicKey key)
f - The Factory to create the Digest to usekey - the public key - ignored if nullnull if no key.
Note: if exception encountered then returns the exception's simple class namegetFingerPrint(Digest, PublicKey)public static String getFingerPrint(Digest d, PublicKey key)
d - The Digest to usekey - the public key - ignored if nullnull if no key.
Note: if exception encountered then returns the exception's simple class nameDigestUtils.getFingerPrint(Digest, byte[], int, int)public static String getFingerPrint(Factory<? extends Digest> f, String s)
f - The Factory to create the Digest to uses - The String to digest - ignored if null/empty,
otherwise its UTF-8 representation is used as input for the fingerprintnull if null/empty input.
Note: if exception encountered then returns the exception's simple class namegetFingerPrint(Digest, String, Charset)public static String getFingerPrint(Factory<? extends Digest> f, String s, Charset charset)
f - The Factory to create the Digest to uses - The String to digest - ignored if null/emptycharset - The Charset to use in order to convert the
string to its byte representation to use as input for the fingerprintnull if null/empty input
Note: if exception encountered then returns the exception's simple class nameDigestUtils.getFingerPrint(Digest, String, Charset)public static String getFingerPrint(Digest d, String s)
d - The Digest to uses - The String to digest - ignored if null/empty,
otherwise its UTF-8 representation is used as input for the fingerprintnull if null/empty input.
Note: if exception encountered then returns the exception's simple class nameDigestUtils.getFingerPrint(Digest, String, Charset)public static String getFingerPrint(Digest d, String s, Charset charset)
d - The Digest to use to calculate the fingerprints - The string to digest - ignored if null/emptycharset - The Charset to use in order to convert the
string to its byte representation to use as input for the fingerprintnull if null/empty input.
Note: if exception encountered then returns the exception's simple class nameDigestUtils.getFingerPrint(Digest, String, Charset)public static String getKeyType(KeyPair kp)
kp - a key pair - ignored if null. If the private
key is non-null then it is used to determine the type,
otherwise the public one is used.null if cannot determine itgetKeyType(Key)public static String getKeyType(Key key)
key - a public or private keynull if cannot determine itpublic static PublicKey findMatchingKey(PublicKey key, PublicKey... keySet)
key - The PublicKey to be checked - ignored if nullkeySet - The keys to be searched - ignored if null/emptyPublicKey from the keys or null if
no match foundcompareKeys(PublicKey, PublicKey)public static PublicKey findMatchingKey(PublicKey key, Collection<? extends PublicKey> keySet)
key - The PublicKey to be checked - ignored if nullkeySet - The keys to be searched - ignored if null/emptyPublicKey from the keys or null if
no match foundcompareKeys(PublicKey, PublicKey)public static boolean compareKeys(PrivateKey k1, PrivateKey k2)
public static boolean compareRSAKeys(RSAPrivateKey k1, RSAPrivateKey k2)
public static boolean compareDSAKeys(DSAPrivateKey k1, DSAPrivateKey k2)
public static boolean compareECKeys(ECPrivateKey k1, ECPrivateKey k2)
public static boolean compareRSAKeys(RSAPublicKey k1, RSAPublicKey k2)
public static boolean compareDSAKeys(DSAPublicKey k1, DSAPublicKey k2)
public static boolean compareECKeys(ECPublicKey k1, ECPublicKey k2)
public static boolean compareECParams(ECParameterSpec s1, ECParameterSpec s2)
Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.