JAVA加密解密工具
import lombok. extern. slf4j. Slf4j ;
import org. jasypt. encryption. pbe. PooledPBEStringEncryptor ;
import org. jasypt. encryption. pbe. config. SimpleStringPBEConfig ;
@Slf4j
public class JasyptUtil { public static String encryptPwd ( String salt, String value) { PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor ( ) ; encryptor. setConfig ( cryPTor ( salt) ) ; String result = encryptor. encrypt ( value) ; return result; } public static String decyptPwd ( String salt, String value) { PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor ( ) ; encryptor. setConfig ( cryPTor ( salt) ) ; String result = encryptor. decrypt ( value) ; return result; } public static SimpleStringPBEConfig cryPTor ( String password) { SimpleStringPBEConfig config = new SimpleStringPBEConfig ( ) ; config. setPassword ( password) ; config. setAlgorithm ( "PBEWithMD5AndDES" ) ; config. setKeyObtentionIterations ( "1000" ) ; config. setPoolSize ( "1" ) ; config. setProviderName ( "SunJCE" ) ; config. setSaltGeneratorClassName ( "org.jasypt.salt.RandomSaltGenerator" ) ; config. setStringOutputType ( "base64" ) ; return config; } private static final String SALT = "^&zzz.com" ; public static void main ( String [ ] args) { String encPwd = JasyptUtil . encryptPwd ( SALT , "12345678" ) ; log. info ( "加密后的值为: {}" , encPwd) ; String decPwd = JasyptUtil . decyptPwd ( SALT , "fI8z1zmuUk3Qk9uwFcu+tJtOFEeE6i7F9RSutYW4zXvQuX/Xx7echxiJXUjXf3XGqV19fj7FFvI=" ) ; log. info ( "解密后的值为: {}" , decPwd) ; }
}