Example #1
0
  private static void testEncryptDecrypt(Cipher c, Cipher d, String string, int key, int value)
      throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
    byte[] data = new byte[3 + 4 + 4];
    byte[] output = new byte[c.getOutputSize(data.length)];
    byte[] result = new byte[3 + 4 + 4];

    byte[] salt = string.getBytes();

    System.arraycopy(salt, 0, data, 0, salt.length);

    intToByteArray2(key, data, 3);
    intToByteArray2(value, data, 7);

    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");
    }
  }