【发布时间】:2018-03-18 02:42:27
【问题描述】:
我正在尝试编写一个非常简单的程序来加密和解密字符串:
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
我做错了什么?
【问题讨论】:
标签: java spring-boot encryption spring-security spring-data-jpa