Class PKCS5KeySpec

  • All Implemented Interfaces:
    java.security.spec.KeySpec

    public class PKCS5KeySpec
    extends java.lang.Object
    implements java.security.spec.KeySpec
    Specification for a "generalized" PBE key. While a PBEKey is derived from a password and is used in the PBEWithMD5andDES cipher, a PKCS5Key is derived from a password and can be used in any PBES1 encryption schemes (for example, PBEWithMD5AndDES, PBEWithMD2AndRC2, PBEWithSHAAndTripleDES, etc).

    Note that this class stores passwords as char arrays instead of String objects (which would seem more logical), because the String class is immutable and there is no way to overwrite its internal value when the password stored in it is no longer needed. Hence, this class requests the password as a char array, so it can be overwritten when done.

    • Constructor Summary

      Constructors 
      Constructor Description
      PKCS5KeySpec​(char[] password, java.lang.String alg)
      Constructor that takes a password and an algorithm.
    • Constructor Detail

      • PKCS5KeySpec

        public PKCS5KeySpec​(char[] password,
                            java.lang.String alg)
        Constructor that takes a password and an algorithm.

        Note that the given password is cloned before it is stored in the new PKCS5KeySpec object.

        Parameters:
        password - the password.
        alg - the algorithm.
    • Method Detail

      • getPassword

        public final char[] getPassword()
        Returns the password.

        Note that this method returns a reference to the password. It is the caller's responsibility to zero out the password information after it is no longer needed.

        Returns:
        the password
      • getAlgorithm

        public final java.lang.String getAlgorithm()
        Returns the algorithm.
        Returns:
        the algorithm
      • finalize

        @Deprecated
        protected void finalize()
        Deprecated.
        Ensures that the password characters of this spec are set to blanks when there are no more references to it.
        Overrides:
        finalize in class java.lang.Object