public static String decryptPayload(byte[] payload, byte[] key) {
		int length = payload.length;
		int length16 = length % 16;
		int length64 = length % 64;

		if (length == 0) {

			return null;

		} else if (length16 == 0) {
			// ecb, plain
			return Utils.decodeAES("ecb", null, payload, key);

		} else if (length64 == 0 || length64 == 24 || length64 == 44) {

			// ecb, base64
			return Utils.decodeAES("ecb", null,
					Utils.decodeBase64String(new String(payload)), key);

		} else if (length16 == 1) {

			// ecb, plain
			ByteBuffer buf = ByteBuffer.wrap(payload);
			byte[] iv = new byte[16];
			byte[] data = new byte[payload.length - 17]; // all the bytes after
			buf.get(); // Throw away the first byte
			buf.get(iv);
			buf.get(data);
			return Utils.decodeAES("cbc", iv, data, key);

		} else if (length64 == 6 || length64 == 26 || length64 == 50) {

			// cbc, base64
			ByteBuffer buf = ByteBuffer.wrap(payload);
			byte[] iv = new byte[25];
			byte[] data = new byte[payload.length - 26]; // all the bytes after
			buf.get(); // Throw away the first byte
			buf.get(iv);
			buf.get(data);
			return Utils.decodeAES("cbc",
					Utils.decodeBase64String(new String(iv)),
					Utils.decodeBase64String(new String(data)), key);

		}
		return null;
	}