public byte[] getEncoded() {
    SubjectPublicKeyInfo info =
        new SubjectPublicKeyInfo(
            new AlgorithmIdentifier(
                OIWObjectIdentifiers.elGamalAlgorithm,
                new ElGamalParameter(elSpec.getP(), elSpec.getG()).getDERObject()),
            new DERInteger(y));

    return info.getDEREncoded();
  }
 public DHParameterSpec getParams() {
   return new DHParameterSpec(elSpec.getP(), elSpec.getG());
 }
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeObject(this.getY());
   out.writeObject(elSpec.getP());
   out.writeObject(elSpec.getG());
 }