private static void testEncryptDecryptLong( Cipher c, Cipher d, String string, long key, long value) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException { byte[] data = new byte[3 + 8 + 8]; byte[] output = new byte[c.getOutputSize(data.length)]; byte[] result = new byte[3 + 8 + 8]; byte[] salt = string.getBytes(); System.arraycopy(salt, 0, data, 0, salt.length); longToByteArray2(key, data, 3); longToByteArray2(value, data, 11); c.doFinal(data, 0, data.length, output); d.doFinal(output, 0, output.length, result); System.out.println("in: " + toHex(data)); System.out.println("enc: " + toHex(output)); System.out.println("dec: " + toHex(result)); for (int i = 0; i < data.length; i++) { if (data[i] != result[i]) throw new IllegalStateException("darn gosh"); } }