Class PaillierPublicKey

java.lang.Object
edu.fiu.adwise.homomorphic_encryption.paillier.PaillierPublicKey
All Implemented Interfaces:
PaillierKey, Serializable, Key, PublicKey

public final class PaillierPublicKey extends Object implements Serializable, PaillierKey, PublicKey
Represents the public key for the Paillier cryptosystem. This class implements the Serializable, Paillier_Key, PublicKey, Runnable, and CipherConstants interfaces. It provides methods for key generation and serialization for encryption operations.
See Also:
  • Field Details

    • key_size

      public final int key_size
      The size of the key in bits.
  • Constructor Details

    • PaillierPublicKey

      public PaillierPublicKey(int key_size, BigInteger n, BigInteger modulus, BigInteger g)
      Constructs a Paillier public 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).
      modulus - The modulus (n^2).
      g - The generator g.
  • Method Details

    • ZERO

      public BigInteger ZERO() throws HomomorphicException
      Retrieves the encryption of zero using this public key.
      Returns:
      The encryption of zero as a BigInteger.
      Throws:
      HomomorphicException - If an error occurs during encryption.
    • toString

      public String toString()
      Returns a string representation of the public key.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the public key.
    • writeKey

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

      public static PaillierPublicKey readKey(String paillier_public_key) throws IOException, ClassNotFoundException
      Reads a public key from a file.
      Parameters:
      paillier_public_key - The file path to read the public key from.
      Returns:
      The PaillierPublicKey object.
      Throws:
      IOException - If an I/O error occurs.
      ClassNotFoundException - If the class of the serialized object cannot be found.
    • 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 ("X.509").
    • 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 public 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.