Class BCDHPrivateKey

  • All Implemented Interfaces:
    java.io.Serializable, java.security.Key, java.security.PrivateKey, javax.crypto.interfaces.DHKey, javax.crypto.interfaces.DHPrivateKey, javax.security.auth.Destroyable, PKCS12BagAttributeCarrier

    public class BCDHPrivateKey
    extends java.lang.Object
    implements javax.crypto.interfaces.DHPrivateKey, javax.security.auth.Destroyable, PKCS12BagAttributeCarrier
    See Also:
    Serialized Form
    • Constructor Detail

      • BCDHPrivateKey

        protected BCDHPrivateKey()
      • BCDHPrivateKey

        public BCDHPrivateKey​(PrivateKeyInfo info)
                       throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getAlgorithm

        public java.lang.String getAlgorithm()
        Specified by:
        getAlgorithm in interface java.security.Key
      • getFormat

        public java.lang.String getFormat()
        return the encoding format we produce in getEncoded().
        Specified by:
        getFormat in interface java.security.Key
        Returns:
        the string "PKCS#8"
      • getEncoded

        public byte[] getEncoded()
        Return a PKCS8 representation of the key. The sequence returned represents a full PrivateKeyInfo object.
        Specified by:
        getEncoded in interface java.security.Key
        Returns:
        a PKCS8 representation of the key.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getParams

        public javax.crypto.spec.DHParameterSpec getParams()
        Specified by:
        getParams in interface javax.crypto.interfaces.DHKey
      • getX

        public java.math.BigInteger getX()
        Specified by:
        getX in interface javax.crypto.interfaces.DHPrivateKey
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • destroy

        public void destroy()
        Destroy this key, clearing the key material it holds.

        The private value is held as a BigInteger, which is immutable and so cannot be zeroized in place - destruction drops the internal reference so the value becomes unreachable (cleared on garbage collection). A PKCS#8 PrivateKeyInfo retained from decoding is dropped with it, and the underlying DHPrivateKeyParameters object, where one is held, is destroyed as well, so keys sharing it are invalidated too. The (public) domain parameters are retained. After destruction isDestroyed() returns true, the secret-bearing accessors (getEncoded() and getX()) throw IllegalStateException, the key can no longer be serialized, and it is equal only to itself; hashCode() retains its pre-destruction value.

        Specified by:
        destroy in interface javax.security.auth.Destroyable
      • isDestroyed

        public boolean isDestroyed()
        Specified by:
        isDestroyed in interface javax.security.auth.Destroyable