0
我想寫一個非常簡單的程序進行加密和解密的字符串:春季安全:簡單的加密/解密不工作:InvalidKeyException將
String password = "kdfljxcasd";
String encodeThat = "Hello World + some special chars!^^-";
String salt = KeyGenerators.string().generateKey();
BytesEncryptor encryptor = Encryptors.standard(password, salt);
// breakpoint steping doesn't reach that point - it gets stuck here for some reason...
byte[] encrypted = encryptor.encrypt(encodeThat.getBytes());
byte[] decrypted = encryptor.decrypt(encrypted);
System.out.println("Before encryption: " + encodeThat);
System.out.println("Encrypted: " + encrypted.toString());
System.out.println("After encryption: " + decrypted.toString());
但由於某些原因,我從來沒有得到一個加密的價值。當我打電話給enryptor.encrypt()
它永遠不會達到那一點。
,我發現了以下異常:
'Unable to initialize due to invalid secret key' java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key
我在做什麼錯?
是有辦法做到這一點,無需任何外部罐子? – naoru