Class DestroyableSecretKey

    • Constructor Detail

      • DestroyableSecretKey

        public DestroyableSecretKey​(byte[] key,
                                    int offset,
                                    int len,
                                    String algorithm)
        Creates a new destroyable secret key, copying of the provided raw key bytes.
        Parameters:
        key - A byte[] holding the key material (relevant part will get copied)
        offset - The offset within key where the key starts
        len - The number of bytes beginning at offset to read from key
        algorithm - The algorithm name
    • Method Detail

      • from

        public static DestroyableSecretKey from​(Key secretKey)
        Casts or converts a given SecretKey to a DestroyableSecretKey
        Parameters:
        secretKey - The secret key
        Returns:
        Either the provided or a new key, depending on whether the provided key is already a DestroyableSecretKey
      • generate

        public static DestroyableSecretKey generate​(SecureRandom csprng,
                                                    String algorithm,
                                                    int keyLenBytes)
        Creates a new key of given length and for use with given algorithm using entropy from the given csprng.
        Parameters:
        csprng - A cryptographically secure random number source
        algorithm - The key algorithm
        keyLenBytes - The length of the key (in bytes)
        Returns:
        A new secret key
      • getEncoded

        public byte[] getEncoded()
        Returns the raw key bytes this instance wraps.

        Important: Any change to the returned array will reflect in this key. Make sure to make a local copy if you can't rule out mutations.

        Specified by:
        getEncoded in interface Key
        Returns:
        A byte array holding the secret key
      • copy

        public DestroyableSecretKey copy()
        Returns an independent copy of this key
        Returns:
        New copy of this
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object