要加密我使用的密码(从http://www.jasypt.org/encrypting-texts.html修改):
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(myEncryptionPassword);
String myEncryptedText = textEncryptor.encrypt(myText);
String plainText = textEncryptor.decrypt(myEncryptedText);
为什么需要在BasicTextEncryptor上设置密码?
我可能不理解这里的一些基本内容但是这没有意义,尽管它不起作用:
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
String myEncryptedText = textEncryptor.encrypt(myText);
String plainText = textEncryptor.decrypt(myEncryptedText);
解决方法:
它确实有效,它需要密码才能进行加密和解密.为了简化示例,我启动了两个StandardPBEStringEncryptor会话作为加密器和解密器
public static void main(String[] args) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("mySecretPassword");
String encryptedText = encryptor.encrypt("Hello World");
System.out.println("Encrypted text is: " + encryptedText);
StandardPBEStringEncryptor decryptor = new StandardPBEStringEncryptor();
decryptor.setPassword("mySecretPassword");
String decryptedText = decryptor.decrypt(encryptedText);
System.out.println("Decrypted text is: " + decryptedText);
}
输出:
Encrypted text is: +pBbr+KOb7D6Ap/5vYJIUoHbhOruls+L
Decrypted text is: Hello World