Package util;
Import Java.security.Provider;
Import Java.security.Provider.Service;
Import java.security.Security;
Import Java.util.Set;
Import Org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
Import Org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
Import Org.jasypt.util.text.BasicTextEncryptor;
Import Org.jasypt.util.text.StrongTextEncryptor; /** * Jasypt's use and access to JDK-supported cryptography algorithms * 542335496@qq.com * * public class Configencryptutils {private static final STANDARDPBE
Stringencryptor encryptor = new Standardpbestringencryptor ();
static {environmentstringpbeconfig config = new Environmentstringpbeconfig ();
Cipher.getinstance (This.algorithm, This.provider);
Config.setalgorithm ("Pbewithmd5anddes");
Config.setalgorithm ("Pbewithsha1anddesede");
Change this password Config.setpassword ("config") when you use it;
Get the cryptography algorithm supported by JDK provider[] providers = Security.getproviders ();
for (Provider provider:providers) {//System.out.println (Provider.getinfo ()); System.oUt.println (json.tojsonstring (provider));
Set<provider.service> services = Provider.getservices ();
for (Service service:services) {System.out.println (Service.getalgorithm ());
} encryptor.setconfig (config);
public static void Main (string[] args) {String plaintext = ' root ';
String ciphertext = encryptor.encrypt (plaintext);
SYSTEM.OUT.PRINTLN (plaintext + ":" + ciphertext);
SYSTEM.OUT.PRINTLN (ciphertext + ":" + encryptor.decrypt (ciphertext));
ciphertext= "royp2tvbuzid+86p1l8sxg==";
System.out.println (ciphertext+ ":" +encryptor.decrypt (ciphertext));
plaintext = "sa";
ciphertext = Encryptor.encrypt (plaintext);
SYSTEM.OUT.PRINTLN (plaintext + ":" + ciphertext);
Test002 ();
private static void test002 () {//encryption Basictextencryptor Textencryptor = new Basictextencryptor ();
Textencryptor.setpassword ("password");
String newpassword = Textencryptor.encrypt ("123456"); System.out.pRintln (NewPassword);
Decrypt Basictextencryptor TextEncryptor2 = new Basictextencryptor ();
Textencryptor2.setpassword ("password");
String OldPassword = Textencryptor2.decrypt (NewPassword);
System.out.println (OldPassword);
System.out.println ("--------------------------");
Strong encryption algorithm needs to go to JDK website download Jce.jar strongtextencryptor ste = new Strongtextencryptor ();
Encryption Ste.setpassword ("password");
String encyptedresult= ste.encrypt ("123456");
System.out.println ("Encyptedresult:" +encyptedresult);
Decrypt String Dencyptedresult = Ste.decrypt (Encyptedresult);
System.out.println (Dencyptedresult);
}
}
Package Com.jiepu;
Import Java.security.Provider;
Import java.security.Security;
Import Java.security.Provider.Service;
Import Java.util.Set;
Import Org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
Import Org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig; /** * When you put the redaction in the configuration file, Note: ENC (ciphertext) * * @author Yang Shangchang/public class Configencryptutils {public static void main (String
[] args) {//test001 ();
Test002 ();
private static void test002 () {//cryptographic standardpbestringencryptor encryptor = new Standardpbestringencryptor ();
Cryptographic configuration environmentstringpbeconfig config = new Environmentstringpbeconfig ();
Get the cryptography algorithm supported by JDK provider[] providers = Security.getproviders ();
for (Provider provider:providers) {//System.out.println (Provider.getinfo ());
System.out.println (json.tojsonstring (provider));
Set<provider.service> services = Provider.getservices (); for (Service Service:services) {System.out.println (Service.getalgorithm ()); }} private static void test001 () {//cryptographic standardpbestringencryptor encryptor = new Standardpbestri
Ngencryptor ();
Cryptographic configuration environmentstringpbeconfig config = new Environmentstringpbeconfig ();
Config.setalgorithm ("Pbewithmd5anddes");
Change this password Config.setpassword ("Apdplat") at the time of use;
Application of encryption Configuration des algorithm encryptor.setconfig (config);
String plaintext = "root";
Encrypted String ciphertext = encryptor.encrypt (plaintext);
SYSTEM.OUT.PRINTLN (plaintext + "==>" + ciphertext);
String Result=encryptor.decrypt (ciphertext);
SYSTEM.OUT.PRINTLN (ciphertext + "==>" + result); }
}
http://my.oschina.net/apdplat/blog/405306