gpt4 book ai didi

java - 为什么在加密文本时使用 Jasypt 设置密码?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:56:22 25 4
gpt4 key购买 nike

加密我使用的密码(修改自 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 session 作为加密器和解密器

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

关于java - 为什么在加密文本时使用 Jasypt 设置密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20176040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com