Tag: javax.crypto

鉴于最后的块没有正确填充

我想实现基于密码的encryptionalgorithm,但我得到这个exception: javax.crypto.BadPaddingException:给定的最终块未正确填充 可能是什么问题? (我是Java新手。) 这是我的代码: public class PasswordCrypter { private Key key; public PasswordCrypter(String password) { try{ KeyGenerator generator; generator = KeyGenerator.getInstance("DES"); SecureRandom sec = new SecureRandom(password.getBytes()); generator.init(sec); key = generator.generateKey(); } catch (Exception e) { e.printStackTrace(); } } public byte[] encrypt(byte[] array) throws CrypterException { try{ Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); return cipher.doFinal(array); […]