Java加密包--Jasypt

来源:互联网 发布:linux 网桥 编辑:程序博客网 时间:2024/06/05 18:01

今天需要读取一个properties文件,里面存取用户名和密码,但了为安全起见,采取加密的方式,在网上搜了了一下,发现有几种方式,但个人觉得简单的还是用下面的开源jar来实现。最新版本已经发布到了1.7了。

 

Jasypt这个Java类包为开发人员提供一种简单的方式来为项目增加加密功能,包括:密码Digest认证,文本和对象加密,集成hibernate,Spring Security(Acegi)来增强密码管理。Jasypt开发团队推出了Java加密工具Jasypt 1.4,它可与Spring Framework、Hibernate和Acegi Security集成。 

  与项目有关的一位开发者表示,Jasypt是一个Java库,可以使开发者不需太多操作来给Java项目添加基本加密功能,而且不需要知道加密原理。

  Jasypt也即Java Simplified Encryption是Sourceforge.net上的一个开源项目。在当地时间11月23号的通告中,Jasypt 1.4的新特征包括:加密属性文件(encryptable properties files)、Spring Framework集成、加密Hibernate数据源配置、新的命令行工具、URL加密的Apache wicket集成以及升级文档。

  根据Jasypt文档,该技术可用于加密任务与应用程序,例如加密密码、敏感信息和数据通信、创建完整检查数据的sums. 其他性能包括高安全性、基于标准的加密技术、可同时单向和双向加密的加密密码、文本、数字和二进制文件。Jasypt也可以与Acegi Security整合也即Spring Security。Jasypt亦拥有加密应用配置的集成功能,而且提供一个开放的API从而任何一个Java Cryptography Extension都可以使用Jasypt。

  Jasypt还符合RSA标准的基于密码的加密,并提供了无配置加密工具以及新的、高可配置标准的加密工具。

 

 

jasypt开源项目主页

 

项目地址:http://www.jasypt.org/

 

Java代码  收藏代码
  1. import org.jasypt.util.text.BasicTextEncryptor;  
  2. import org.jasypt.util.text.StrongTextEncryptor;  
  3.   
  4.   
  5. public class EncypterTest {  
  6.   
  7.     public static void main(String[] args) {  
  8.          //加密     
  9.         BasicTextEncryptor textEncryptor = new BasicTextEncryptor();     
  10.         textEncryptor.setPassword("password");    
  11.         String newPassword = textEncryptor.encrypt("123456");    
  12.         System.out.println(newPassword);    
  13. //        解密     
  14.         BasicTextEncryptor textEncryptor2 = new BasicTextEncryptor();     
  15.         textEncryptor2.setPassword("password");     
  16.         String oldPassword = textEncryptor2.decrypt(newPassword);       
  17.         System.out.println(oldPassword);    
  18.         System.out.println("--------------------------");  
  19.         /** 
  20.          * Utility class for easily performing high-strength encryption of texts.  
  21.          *  This class internally holds a StandardPBEStringEncryptor configured this way:  
  22.          *  Algorithm: PBEWithMD5AndTripleDES.  
  23.          *  Key obtention iterations: 1000.  
  24.          *  The required steps to use it are:  
  25.          *  Create an instance (using new).  
  26.          *  Set a password (using setPassword(String)).  
  27.          *  Perform the desired encrypt(String) or decrypt(String) operations.  
  28.          *  To use this class, you may need to download and install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files.  
  29.          *  This class is thread-safe.  
  30.          */  
  31.         StrongTextEncryptor ste = new StrongTextEncryptor();  
  32.         //加密  
  33.         ste.setPassword("password");  
  34.         String encyptedResult= ste.encrypt("123456");  
  35.         System.out.println("encyptedResult:"+encyptedResult);  
  36.         //解密  
  37.         String dencyptedResult = ste.decrypt(encyptedResult);  
  38.         System.out.println(dencyptedResult);  
  39.           
  40.           
  41.     }  
  42. }  
  43. //NbxTTz53iW0d1GUphknPqg== 

原创粉丝点击