次の方法を使用して暗号化された文字列を復号化しようとしていますが、例外に行き詰まりました。
暗号化された文字列を以下のメソッドに送信しようとしていますが、バイト [] を取得できず、文字列をバイト [] に変換中に数値形式の例外が発生します。
私の復号化方法:
public static String decrypt(String seed, String encrypted) throws Exception {
byte[] seedByte = seed.getBytes();
System.arraycopy(seedByte, 0, key, 0, ((seedByte.length < 16) ? seedByte.length : 16));
String base64 = new String(Base64.decode(encrypted, 0));
byte[] rawKey = getRawKey(seedByte);
byte[] enc = toByte(base64);
byte[] result = decrypt(rawKey, enc);
return new String(result);
}
ここに私の toByte(String) メソッドがあります:
public static byte[] toByte(String hexString) {
int len = hexString.length() / 2;
byte[] result = new byte[len];
for (int i = 0; i < len; i++)
result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16).byteValue();
return result;
}
私が得ている例外:
08-15 13:03:04.748: W/System.err(10013): java.lang.NumberFormatException: Invalid int: "@��"
08-15 13:03:04.748: W/System.err(10013): at java.lang.Integer.invalidInt(Integer.java:138)
08-15 13:03:04.748: W/System.err(10013): at java.lang.Integer.parse(Integer.java:375)
08-15 13:03:04.748: W/System.err(10013): at java.lang.Integer.parseInt(Integer.java:366)
08-15 13:03:04.748: W/System.err(10013): at java.lang.Integer.valueOf(Integer.java:510)
08-15 13:03:04.748: W/System.err(10013): at com.example.aes.EncodeDecodeAES.toByte(EncodeDecodeAES.java:226)
08-15 13:03:04.748: W/System.err(10013): at com.example.aes.EncodeDecodeAES.decrypt(EncodeDecodeAES.java:69)
08-15 13:03:04.748: W/System.err(10013): at com.example.aes.MainActivity$1.run(MainActivity.java:94)
なぜこのエラーが発生するのか、本当にわかりませんでした。
提案してください。