/** * Generates the public/private key pair from the init params * * @throws Exception */ public void initKeyPair() throws Exception { // generate keys according to the specified algorithms // generate publicKey and Private Key KeyPairGenerator KpairGen = null; if (asymProvider != null && !asymProvider.trim().isEmpty()) KpairGen = KeyPairGenerator.getInstance(getAlgorithm(asymAlgorithm), asymProvider); else KpairGen = KeyPairGenerator.getInstance(getAlgorithm(asymAlgorithm)); KpairGen.initialize(asymInit, new SecureRandom()); Kpair = KpairGen.generateKeyPair(); // set up the Cipher to decrypt secret key responses encrypted with our key if (asymProvider != null && !asymProvider.trim().isEmpty()) asymCipher = Cipher.getInstance(asymAlgorithm, asymProvider); else asymCipher = Cipher.getInstance(asymAlgorithm); asymCipher.init(Cipher.DECRYPT_MODE, Kpair.getPrivate()); log.debug("asym algo initialized"); }
/** send client's public key to server and request server's public key */ private void sendKeyRequest() { Message newMsg = new Message(keyServerAddr, local_addr, Kpair.getPublic().getEncoded()) .putHeader(this.id, new EncryptHeader(EncryptHeader.KEY_REQUEST, getSymVersion())); down_prot.down(new Event(Event.MSG, newMsg)); }