Class PaillierPrivateKey

java.lang.Object
edu.fiu.adwise.homomorphic_encryption.paillier.PaillierPrivateKey
All Implemented Interfaces:
PaillierKey, Serializable, Key, PrivateKey, Destroyable

public final class PaillierPrivateKey extends Object implements Serializable, PaillierKey, PrivateKey
This class represents a private key in the Paillier cryptosystem. It implements the PaillierKey and PrivateKey interfaces and is also serializable.
See Also:
  • Constructor Details

    • PaillierPrivateKey

      public PaillierPrivateKey(int key_size, BigInteger n, BigInteger mod, BigInteger lambda, BigInteger mu, BigInteger g, BigInteger alpha)
      Constructs a Paillier private key with the specified parameters.
      Parameters:
      key_size - The size of the key in bits.
      n - The value of n (product of two primes p and q).
      mod - The modulus (n^2).
      lambda - The Carmichael's function value.
      mu - The modular inverse of lambda mod n.
      g - The generator g.
      alpha - The smallest divisor of lcm(p-1, q-1).
  • Method Details

    • writeKey

      public void writeKey(String paillier_private_key_file) throws IOException
      Writes the private key to a file.
      Parameters:
      paillier_private_key_file - The file path to save the private key.
      Throws:
      IOException - If an I/O error occurs.
    • readKey

      public static PaillierPrivateKey readKey(String paillier_private_key) throws IOException, ClassNotFoundException
      Reads a private key from a file.
      Parameters:
      paillier_private_key - The file path to read the private key from.
      Returns:
      The PaillierPrivateKey object.
      Throws:
      IOException - If an I/O error occurs.
      ClassNotFoundException - If the class of the serialized object cannot be found.
    • toString

      public String toString()
      Returns a string representation of the private key, omitting secret parameters.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the private key.
    • getN

      public BigInteger getN()
      Retrieves the value of n, which is part of the Paillier key.
      Specified by:
      getN in interface PaillierKey
      Returns:
      The value of n as a BigInteger.
    • getModulus

      public BigInteger getModulus()
      Retrieves the modulus used in the Paillier cryptosystem.
      Specified by:
      getModulus in interface PaillierKey
      Returns:
      The modulus as a BigInteger.
    • getAlgorithm

      public String getAlgorithm()
      Returns the algorithm name for this key.
      Specified by:
      getAlgorithm in interface Key
      Returns:
      The algorithm name ("Paillier").
    • getFormat

      public String getFormat()
      Returns the format of the key encoding.
      Specified by:
      getFormat in interface Key
      Returns:
      The format ("PKCS#8").
    • getEncoded

      public byte[] getEncoded()
      Returns the encoded form of the key.
      Specified by:
      getEncoded in interface Key
      Returns:
      The encoded key as a byte array, or null if not supported.
    • equals

      public boolean equals(Object o)
      Compares this private key with another object for equality.
      Overrides:
      equals in class Object
      Parameters:
      o - The object to compare with.
      Returns:
      True if the objects are equal, false otherwise.