Package net.i2p.data

Class PrivateKey

  • All Implemented Interfaces:
    Destroyable, DataStructure

    public class PrivateKey
    extends SimpleDataStructure
    implements Destroyable
    Defines the PrivateKey as defined by the I2P data structure spec. A private key is 256byte Integer. The private key represents only the exponent, not the primes, which are constant and defined in the crypto spec. As of release 0.9.38, keys of arbitrary length and type are supported. See EncType.
    Author:
    jrandom
    • Field Detail

      • KEYSIZE_BYTES

        public static final int KEYSIZE_BYTES
    • Constructor Detail

      • PrivateKey

        public PrivateKey()
      • PrivateKey

        public PrivateKey​(EncType type)
        Parameters:
        type - non-null
        Since:
        0.9.38
      • PrivateKey

        public PrivateKey​(byte[] data)
      • PrivateKey

        public PrivateKey​(EncType type,
                          byte[] data)
        Parameters:
        type - non-null
        data - must be non-null
        Since:
        0.9.38
      • PrivateKey

        public PrivateKey​(EncType type,
                          byte[] data,
                          PublicKey pubKey)
        Parameters:
        type - non-null
        data - must be non-null
        pubKey - corresponding pubKey to be cached
        Since:
        0.9.44
      • PrivateKey

        public PrivateKey​(String base64Data)
                   throws DataFormatException
        constructs from base64
        Parameters:
        base64Data - a string of base64 data (the output of .toBase64() called on a prior instance of PrivateKey
        Throws:
        DataFormatException
    • Method Detail

      • getType

        public EncType getType()
        Returns:
        non-null
        Since:
        0.9.38
      • toPublic

        public PublicKey toPublic()
        Derives a new PublicKey object derived from the secret contents of this PrivateKey. As of 0.9.44, the PublicKey is cached.
        Returns:
        a PublicKey object
        Throws:
        IllegalArgumentException - on bad key
      • destroy

        public void destroy()
        javax.security.auth.Destroyable interface
        Specified by:
        destroy in interface Destroyable
        Since:
        0.9.40
      • isDestroyed

        public boolean isDestroyed()
        javax.security.auth.Destroyable interface
        Specified by:
        isDestroyed in interface Destroyable
        Since:
        0.9.40
      • hashCode

        public int hashCode()
        We assume the data has enough randomness in it, so use the last 4 bytes for speed. Overridden since we use short exponents, so the first 227 bytes are all zero.
        Overrides:
        hashCode in class SimpleDataStructure
      • equals

        public boolean equals​(Object obj)
        Description copied from class: SimpleDataStructure
        Warning - this returns true for two different classes with the same size and same data, e.g. SessionKey and SessionTag, but you wouldn't put them in the same Set, would you?
        Overrides:
        equals in class SimpleDataStructure