以下java代碼嘗試解密用C#代碼加密的QR碼中編碼的字符串。它似乎無法解密字符串。有沒有這樣做的簡單方法?Java使用預定義的128位密鑰進行AES加密和解密
//string encrypted contains the string of the encoded characters.
String encrypted = intent.getStringExtra("SCAN_RESULT");
//converting the string into a byte array
byte[] byteEncrypted = encrypted.getBytes();
//instantiating the AES cipher object
Cipher cipher = Cipher.getInstance("AES");
//Predefined public-key
byte[] skey = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
//creating a secretKeySpec
SecretKeySpec skeyspec = new SecretKeySpec(skey, "AES");
//initializing the cipher to Decrypt
cipher.init(Cipher.DECRYPT_MODE, skeyspec);
final byte[] decrypt = cipher.doFinal(byteEncrypted);
//decrypting the string
String contents = new String(decrypt, "UTF-8");
找出C#代碼究竟是怎麼加密和結果編碼爲QR碼。沒有這個,只有瘋狂的猜測。 –
我刪除了公鑰加密標籤,因爲我沒有看到這個問題與公鑰加密有什麼關係,儘管代碼中有評論。 – Fantius