为什么在加密文本时使用jasypt设置密码? [英] Why set a password using jasypt when encrypting text?
本文介绍了为什么在加密文本时使用jasypt设置密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要加密密码(从 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上设置密码?
Why is a password required to be set on BasicTextEncryptor ?
我可能在这里不了解一些基本知识,但这虽然没有用,但这没有任何意义:
I may be not understanding something fundamental here but does this not make sense, although it does not work :
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
String myEncryptedText = textEncryptor.encrypt(myText);
String plainText = textEncryptor.decrypt(myEncryptedText);
推荐答案
它确实有效,并且确实需要密码进行加密和解密.为了简化示例,我已经启动了两个StandardPBEStringEncryptor会话,分别作为加密器和解密器
It does work and it does require password for encryption and decryption. To simplify the example I have initiated two sessions of StandardPBEStringEncryptor as encryptor and decryptor
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
这篇关于为什么在加密文本时使用jasypt设置密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文