Use of jasypt and access to JDK-supported cryptography algorithms

Source: Internet
Author: User
Tags decrypt
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.