Class KeyUtil

    • Method Detail

      • getParameters

        public static AlgorithmParameterSpec getParameters​(Key key)
        Attempt to acquire parameters from the given key.
        Parameters:
        key - the key (must not be null)
        Returns:
        the parameters, or null if no known parameters are available
      • getParameters

        public static <P extends AlgorithmParameterSpec> P getParameters​(Key key,
                                                                         Class<P> paramSpecClass)
        Attempt to acquire parameters of the given type from the given key.
        Type Parameters:
        P - the parameter specification type
        Parameters:
        key - the key (must not be null)
        paramSpecClass - the parameter specification class (must not be null)
        Returns:
        the parameters, or null if no known parameters of the given type are available
      • hasParameters

        public static boolean hasParameters​(Key key,
                                            AlgorithmParameterSpec parameters)
        Determine if the given key has parameters which match the given parameters.
        Parameters:
        key - the key (must not be null)
        parameters - the parameters (must not be null)
        Returns:
        true if the parameters match, false otherwise
      • parametersEqual

        public static boolean parametersEqual​(AlgorithmParameterSpec p1,
                                              AlgorithmParameterSpec p2)
        Attempt to determine if two algorithm parameter specifications are equal. This method will return true if the parameters are definitely the same, or false if they are not definitely equal or equivalency cannot be determined.
        Parameters:
        p1 - the first parameter specification (must not be null)
        p2 - the second parameter specification (must not be null)
        Returns:
        true if the parameters are definitely equal, false otherwise
      • parametersHashCode

        public static int parametersHashCode​(AlgorithmParameterSpec param)
        Attempt to get a stable hash code for the given parameter specification. If a stable hash code cannot be acquired, the hash code of the class is returned, which results in correct (if non-optimal) behavior. If the parameter is null, a hash code of zero is returned.
        Parameters:
        param - the parameter specification
        Returns:
        the hash code
      • hasSameParameters

        public static boolean hasSameParameters​(Key key1,
                                                Key key2)
        Attempt to determine if the two keys have the same parameters. This method returns true if the keys definitely have the same parameters, or false if they do not or if parameter equivalency cannot be determined.
        Parameters:
        key1 - the first key (must not be null)
        key2 - the second key (must not be null)
        Returns:
        true if the parameters are definitely equal, false otherwise
      • cloneKey

        public static <T extends Key> T cloneKey​(Class<T> expectType,
                                                 T key)
        Attempt to create a safe clone of the given key object. This algorithm first checks to see if the key's class implements 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.
        Parameters:
        expectType - the expected result type (must not be null)
        key - the key object
        Returns:
        the cloned key, or the original if the key type is not destroyable