@Test public void testPackString() throws Exception { byte[] bytes = AES.pack(unpaddedtext); assertTrue("Original String Length was missing", bytes[3] == 13); assertThat("Original String was missing", new String(Arrays.copyOfRange(bytes, 4, 17), "UTF-8"), is(unpaddedtext)); assertThat("Array was correctly padded", bytes.length, is(32)); }
public static byte[] pack(byte[] bytes) { int length = bytes.length + 4; int packedLength = length + (((length % 16) != 0) ? (16 - (length % 16)) : 0); byte[] result = new byte[packedLength]; result[0] = (byte) ((bytes.length & 0xFF000000) >> 24); result[1] = (byte) ((bytes.length & 0x00FF0000) >> 16); result[2] = (byte) ((bytes.length & 0x0000FF00) >> 8); result[3] = (byte) ((bytes.length & 0x000000FF) >> 0); System.arraycopy(bytes, 0, result, 4, bytes.length); return result; }
AES { public static byte[] pack(byte[] bytes) { int length = bytes.length + 4; int packedLength = length + (((length % 16) != 0) ? (16 - (length % 16)) : 0); byte[] result = new byte[packedLength]; result[0] = (byte) ((bytes.length & 0xFF000000) >> 24); result[1] = (byte) ((bytes.length & 0x00FF0000) >> 16); result[2] = (byte) ((bytes.length & 0x0000FF00) >> 8); result[3] = (byte) ((bytes.length & 0x000000FF) >> 0); System.arraycopy(bytes, 0, result, 4, bytes.length); return result; } }
AES { public static byte[] pack(byte[] bytes) { int length = bytes.length + 4; int packedLength = length + (((length % 16) != 0) ? (16 - (length % 16)) : 0); byte[] result = new byte[packedLength]; result[0] = (byte) ((bytes.length & 0xFF000000) >> 24); result[1] = (byte) ((bytes.length & 0x00FF0000) >> 16); result[2] = (byte) ((bytes.length & 0x0000FF00) >> 8); result[3] = (byte) ((bytes.length & 0x000000FF) >> 0); System.arraycopy(bytes, 0, result, 4, bytes.length); return result; }  }
AES { public static byte[] pack(byte[] bytes) { int length = bytes.length + 4; int packedLength = length + (((length % 16) != 0) ? (16 - (length % 16)) : 0); byte[] result = new byte[packedLength]; result[0] = (byte) ((bytes.length & 0xFF000000) >> 24); result[1] = (byte) ((bytes.length & 0x00FF0000) >> 16); result[2] = (byte) ((bytes.length & 0x0000FF00) >> 8); result[3] = (byte) ((bytes.length & 0x000000FF) >> 0); System.arraycopy(bytes, 0, result, 4, bytes.length); return result; }  static byte[] encrypt(byte[] bytes, byte[] encryptionKey); static byte[] decrypt(byte[] cipherText, byte[] encryptionKey); static byte[] pack(byte[] bytes); static byte[] pack(String string); static byte[] unPackBytes(byte[] bytes); static String unPackString(byte[] bytes); static String encode(byte[] bytesToEncode); static byte[] decode(String stringToDecode); }
AES { public static byte[] pack(byte[] bytes) { int length = bytes.length + 4; int packedLength = length + (((length % 16) != 0) ? (16 - (length % 16)) : 0); byte[] result = new byte[packedLength]; result[0] = (byte) ((bytes.length & 0xFF000000) >> 24); result[1] = (byte) ((bytes.length & 0x00FF0000) >> 16); result[2] = (byte) ((bytes.length & 0x0000FF00) >> 8); result[3] = (byte) ((bytes.length & 0x000000FF) >> 0); System.arraycopy(bytes, 0, result, 4, bytes.length); return result; }  static byte[] encrypt(byte[] bytes, byte[] encryptionKey); static byte[] decrypt(byte[] cipherText, byte[] encryptionKey); static byte[] pack(byte[] bytes); static byte[] pack(String string); static byte[] unPackBytes(byte[] bytes); static String unPackString(byte[] bytes); static String encode(byte[] bytesToEncode); static byte[] decode(String stringToDecode);  }