@Test public void testEncryptDecrypt() throws Exception { ChannelCiphers ciphers = ChannelCiphers.create(ENTROPY); byte[] encrypted = ciphers.getEncryptCipher().doFinal("string 1".getBytes(Charsets.UTF_8)); String decrypted = new String(ciphers.getDecryptCipher().doFinal(encrypted), Charsets.UTF_8); assertEquals("string 1", decrypted); }
@Test public void testMatchingWithKeys() throws Exception { ChannelCiphers ciphers1 = ChannelCiphers.create(ENTROPY); ChannelCiphers ciphers2 = ChannelCiphers.create(ciphers1.getAesKey(), ciphers1.getSpecKey()); byte[] encrypted = ciphers1.getEncryptCipher().doFinal("string 1".getBytes(Charsets.UTF_8)); String decrypted = new String(ciphers2.getDecryptCipher().doFinal(encrypted), Charsets.UTF_8); assertEquals("string 1", decrypted); assertEquals(16, ciphers1.getAesKey().length); assertEquals(16, ciphers1.getSpecKey().length); }