下面的代碼精美的作品在甲骨文的JDK 7的Windows,但無法在Linux上以下錯誤:javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
在該行Cipher.doFinal(ciphertextArray)
這是使用帶有完全相同的Jar文件完全相同的命令行等文字和密碼的值是通過命令行雖然快到了,我懷疑的問題是這裏的某個地方,我只是不知道在哪裏...守則適用於Windows的JDK 7,但不是在Linux上JDK 7
String saltD = text.substring(0,12);
String ciphertext = text.substring(12,text.length());
// BASE64Decode the bytes for the salt and the ciphertext
Base64 decoder = new Base64();
byte[] saltArray = decoder.decode(saltD);
byte[] ciphertextArray = decoder.decode(ciphertext);
// Create the PBEKeySpec with the given password
PBEKeySpec keySpec = new PBEKeySpec(password.trim().toCharArray());
// Get a SecretKeyFactory for PBEWithSHAAndTwofish
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(encryptionMethod);
// Create our key
SecretKey key = keyFactory.generateSecret(keySpec);
// Now create a parameter spec for our salt and iterations
PBEParameterSpec paramSpec = new PBEParameterSpec(saltArray, ITERATIONS);
// Create a cipher and initialize it for encrypting
Cipher cipher = Cipher.getInstance(encryptionMethod);
cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
// Perform the actual decryption
byte[] plaintextArray = cipher.doFinal(ciphertextArray);
return new String(plaintextArray);
爲了確保它不是一個錯誤,我會運行這與每個的最新版本。我懷疑1.7.0_09-icedtea太舊了。 –
所以,爲什麼不使用正在工作的那個;) – Abraham
好吧,所以我只是在另一臺測試機器上安裝了相同的JDK,並且它排除了這一點。所以我調整了這個問題。但我現在記得閱讀某處需要對命令行參數做些什麼的事情,因爲Windows和Linux之間存在細微差別。我只是不記得什麼,何時何地或如何:( –