以下代码在Windows的Oracle JDK 7中运行良好,但在Linux上出现以下错误: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher在行Cipher.doFinal(ciphertextArray)使用javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher进行javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher这是使用完全相同的Jar文件与完全相同的命令行等。文本和密码的值来自命令行,但我怀疑这个问题是在这里的某处,我只是不知道在哪里…
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);
openssl aes-256encryption文件在Windows上不能解密在Linux上
SSL不能在IIS中使用Let's Encrypt解决
CertCreateCertificateContext返回CRYPT_E_ASN1_BADTAG / 8009310b
Certbot无法到达运行django的Nginx webroot
看来,这是由于两个平台上的默认字符集的差异。
您需要确保使用指定的字符集执行String到byte[]转换(反之亦然),而不是依赖平台默认值。
问题是,文本字符串中包含“$”字符,并从Linux中的命令行这些是转义字符。 他们需要在字符串本身转换为“ $”。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。