Package net.i2p.data

Class PrivateKey

  • All Implemented Interfaces:
    Serializable, DataStructure

    public class PrivateKey
    extends SimpleDataStructure
    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. Note that we use short exponents, so all but the last 28.25 bytes are zero. See http://www.i2p2.i2p/how_cryptography for details.
    Author:
    jrandom
    See Also:
    Serialized Form
    • Constructor Detail

      • PrivateKey

        public PrivateKey()
      • PrivateKey

        public PrivateKey​(byte[] data)
      • 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

      • toPublic

        public PublicKey toPublic()
        derives a new PublicKey object derived from the secret contents of this PrivateKey
        Returns:
        a PublicKey object
        Throws:
        IllegalArgumentException - on bad key
      • 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