Java加密包--Jasypt

今天需要讀取一個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== 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章