Jasypt 数据库及中间件密码加解密
    		       		warning:
    		            这篇文章距离上次修改已过450天,其中的内容可能已经有所变动。
    		        
        		                
                
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
 
public class JasyptExample {
    public static void main(String[] args) {
        // 初始化加密器
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword("myEncryptionPassword"); // 设置加密密钥
 
        // 加密
        String myClearTextPassword = "myDbPassword";
        String myEncryptedPassword = encryptor.encrypt(myClearTextPassword);
        System.out.println("加密密码: " + myEncryptedPassword);
 
        // 解密
        String myDecryptedPassword = encryptor.decrypt(myEncryptedPassword);
        System.out.println("解密密码: " + myDecryptedPassword);
    }
}这段代码使用了Jasypt库来加密和解密一个数据库密码。首先,我们创建了一个StandardPBEStringEncryptor实例,并设置了加密密钥。然后,我们使用这个加密器来加密一个明文密码,并输出加密后的密码。最后,我们使用同一个加密器来解密我们之前加密的密码,并输出解密后的密码。这个例子展示了如何在实际应用中使用Jasypt来保护数据库和其他系统的密码。
评论已关闭