Jasypt还符合RSA标准的基于密码的加密,并提供了无配置加密工具以及新的、高可配置标准的加密工具。
jasypt开源项目主页
项目地址:http://www.jasypt.org/
import org.jasypt.util.text.BasicTextEncryptor; import org.jasypt.util.text.StrongTextEncryptor; public class EncypterTest { public static void main(String[] args) { //加密 BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); textEncryptor.setPassword("password"); String newPassword = textEncryptor.encrypt("123456"); System.out.println(newPassword); // 解密 BasicTextEncryptor textEncryptor2 = new BasicTextEncryptor(); textEncryptor2.setPassword("password"); String oldPassword = textEncryptor2.decrypt(newPassword); System.out.println(oldPassword); System.out.println("--------------------------"); /** * Utility class for easily performing high-strength encryption of texts. * This class internally holds a StandardPBEStringEncryptor configured this way: * Algorithm: PBEWithMD5AndTripleDES. * Key obtention iterations: 1000. * The required steps to use it are: * Create an instance (using new). * Set a password (using setPassword(String)). * Perform the desired encrypt(String) or decrypt(String) operations. * To use this class, you may need to download and install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files. * This class is thread-safe. */ StrongTextEncryptor ste = new StrongTextEncryptor(); //加密 ste.setPassword("password"); String encyptedResult= ste.encrypt("123456"); System.out.println("encyptedResult:"+encyptedResult); //解密 String dencyptedResult = ste.decrypt(encyptedResult); System.out.println(dencyptedResult); } } //NbxTTz53iW0d1GUphknPqg==