Class KeyUtil


  • public final class KeyUtil
    extends Object
    Key utility methods.
    Since:
    1.5.0
    Author:
    Farah Juma
    • Constructor Detail

      • KeyUtil

        public KeyUtil()
    • Method Detail

      • getDefaultCompatibleSignatureAlgorithmName

        public static String getDefaultCompatibleSignatureAlgorithmName​(PrivateKey privateKey)
                                                                 throws IllegalArgumentException
        Get the default compatible signature algorithm name for the given private key.
        Parameters:
        privateKey - the private key
        Returns:
        the default compatible signature algorithm name for the given private key or null if the default compatible signature algorithm name cannot not be determined
        Throws:
        IllegalArgumentException - if the key size cannot be determined from the given private key
      • getDefaultCompatibleSignatureAlgorithmName

        public static String getDefaultCompatibleSignatureAlgorithmName​(String keyAlgorithmName,
                                                                        int keySize)
        Get the default compatible signature algorithm name for the given key algorithm name and key size.
        Parameters:
        keyAlgorithmName - the key algorithm name
        keySize - the key size
        Returns:
        the default compatible signature algorithm name for the given key algorithm name and key size or null if the default compatible signature algorithm name cannot not be determined
      • getDefaultMessageDigestAlgorithmName

        private static String getDefaultMessageDigestAlgorithmName​(String keyAlgorithmName,
                                                                   int keySize)
        Get the default message digest algorithm name for the given key algorithm name and key size.
        Parameters:
        keyAlgorithmName - the key algorithm name
        keySize - the key size
        Returns:
        the default message digest algorithm name or null if the default message algorithm name cannot be determined
      • getKeySize

        public static int getKeySize​(Key key)
        Get the key size for the given Key.
        Parameters:
        key - the key
        Returns:
        the key size or -1 if the key size cannot be determined
      • getKeyIdentifier

        public static byte[] getKeyIdentifier​(PublicKey publicKey)
        Get the key identifier, which is composed of the 160-bit SHA-1 hash of the value of the BIT STRING subjectPublicKey (excluding the tag, length, and number of unused bits), as per RFC 3280.
        Parameters:
        publicKey - the public key
        Returns:
        the key identifier