### Question:
Stream { static public byte[] exchange(InputStream is, OutputStream os) throws IOException, InvalidKeyException { final byte[] localSecretKey = X25519.generatePrivateKey(); final byte[] localPublicKey = X25519.publicFromPrivate(localSecretKey); final byte[] wireFormat = new byte[localPublicKey.length + 1]; wireFormat[0] = ECC_X25519; System.arraycopy(localPublicKey, 0, wireFormat, 1, localPublicKey.length); os.write(wireFormat); for (int i = 0, l = wireFormat.length; i < l;) { i += is.read(wireFormat, i, l - i); } if (wireFormat[0] != ECC_X25519) { throw new InvalidKeyException("Peer sent an unknown key format"); } final byte[] peersPublicKey = Arrays.copyOfRange(wireFormat, 1, localPublicKey.length + 1); final byte[] sharedKey = X25519.computeSharedSecret(localSecretKey, peersPublicKey); Stream.PRF prf = instance.new MacBasedPRF("HmacSHA256"); prf.init(sharedKey); byte[] salt = new byte[0]; return PBKDF2(prf, salt, PBKDF2_ITER, PBKDF2_SIZE); }  static byte[] exchange(InputStream is, OutputStream os); static OutputStream encrypt(OutputStream stream, SecretKeySpec aes); static OutputStream encrypt(OutputStream stream, byte[] aesBytes); static InputStream decrypt(InputStream stream, SecretKeySpec aes); static InputStream decrypt(InputStream stream, byte[] aesBytes); static public String ALGORITHM; }### Answer:
@Test public void exchange() throws Exception { System.out.println("StreamTest.exchange"); byte[] input = new byte[33]; random.nextBytes(input); input[0] = 0x19; ByteArrayInputStream bis = new ByteArrayInputStream(input); ByteArrayOutputStream bos = new ByteArrayOutputStream(33); final byte[] sharedKey = Stream.exchange(bis, bos); final byte[] emptyKey = new byte[sharedKey.length]; System.out.println("shared key:"); Hex.dump(sharedKey); assertThat("sharedKey has 32 bytes", sharedKey.length, is(32)); assertThat("sharedKey is not zeros", sharedKey, not(is(emptyKey))); }