Package ass3.program.core.message

Source Code of ass3.program.core.message.PublicKeyRequest

package ass3.program.core.message;

import tools.elgamal.KeyGenerator;
import ass3.program.core.ChatterContext;

public class PublicKeyRequest extends Request {

  /**
   *
   */
  private static final long serialVersionUID = -1257806048691099422L;

  public static final String PRIVATE_KEY = "PrivateKey";

  public static final String PUBLIC_KEY = "PublicKey";

  private int bitLength;

  public PublicKeyRequest(String from, String to, int bitLength) {
    super(from, to);
    this.bitLength = bitLength;
  }

  public int getBitLength() {
    return bitLength;
  }

  public Message respond() {
    // Generate Key Pair and respond the public key, the private key is
    // stored in the context
    KeyGenerator keyGen = new KeyGenerator(bitLength);
    ChatterContext.put(getCk().getA(), PRIVATE_KEY, keyGen.getPrivateKey());
    return new PublicKeyResponse(getTo(), getFrom(), keyGen.getPublicKey());
  }

  @Override
  public Message respondError(int error) {
    Response resp = new PublicKeyResponse(getTo(), getFrom(), null);
    resp.setError(error);
    return resp;
  }
}
TOP

Related Classes of ass3.program.core.message.PublicKeyRequest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.