public Connection encryptConnection ( SecretKey sessionKey , String algorithm ) throws IOException , GeneralSecurityException { Cipher cout = Cipher . getInstance ( algorithm ) ; cout . init ( Cipher . ENCRYPT_MODE , sessionKey , new IvParameterSpec ( sessionKey . getEncoded ( ) ) ) ; CipherOutputStream o = new CipherOutputStream ( out , cout ) ; Cipher cin = Cipher . getInstance ( algorithm ) ; cin . init ( Cipher . DECRYPT_MODE , sessionKey , new IvParameterSpec ( sessionKey . getEncoded ( ) ) ) ; CipherInputStream i = new CipherInputStream ( in , cin ) ; return new Connection ( i , o ) ; }
Upgrades a connection with transport encryption by the specified symmetric cipher .