Java encryption and decryption-jasypt

Source: Internet
Author: User
Tags decrypt
1. Download URL
Http://www.jasypt.org/download.html

2. Rely on Jar
Jasypt-1.9.0.jar

3. Encryption
        The default encryption/decryption algorithm is pbewithmd5anddes
        standardpbestringencryptor encryptor = new Standardpbestringencryptor ();
        Encryptor.setpassword (KEY);
        return Encryptor.encrypt (text);
# Note: Every time you encrypt the ciphertext is not the same;

4. Decryption
        Standardpbestringencryptor encryptor = new Standardpbestringencryptor ();
        Encryptor.setpassword (KEY);
        return Encryptor.decrypt (ciphertext);

5. Sample Code
Package org.demo.encrypt;

Import Org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
	
	public class Encryptutils {//Key private static final String key = "1234567a?"; public static void Main (string[] args) {string ciphertext1 = Encrypt ("ABCDEFG");//wu11fsc0gpgset5au8gxua== String C IPHERTEXT2 = Encrypt ("ABCDEFG");
		esxlhsvk2ym7mgchy2ccgg== System.out.println (CIPHERTEXT1);
		
		System.out.println (CIPHERTEXT2);
		String Text1 = Decrypt (CIPHERTEXT1);
		String Text2 = Decrypt (CIPHERTEXT2);               System.out.println (Text1);               ABCDEFG System.out.println (TEXT2); ABCDEFG}/** * Encryption * @param text Clear * @return redaction */public static string encrypt (String text) {Stan
		Dardpbestringencryptor encryptor = new Standardpbestringencryptor ();
		Encryptor.setpassword (KEY);
	return Encryptor.encrypt (text);
		/** * decryption * @param ciphertext ciphertext * @return plaintext/public static string decrypt (String ciphertext) { StandardpBestringencryptor encryptor = new Standardpbestringencryptor ();
		Encryptor.setpassword (KEY);
	return Encryptor.decrypt (ciphertext); }
}

Related Article

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.