2014-06-09 70 views
1

我可以使用EncryptableProperties使用jasypt加密和解密.properties文件中的憑證。因爲我想使用我自己的算法或算法,如「SHA-512」如何在EncryptableProperties中實現它?Jasypt - 如何使用StrongPasswordEncryptor獲取.properties文件中的憑證

是否有任何方法使用ConfigurablePasswordEncryptor或StrongPasswordEncryptor而不是我EncryptableProperties上的StringEncryptor或TextEncryptor。

StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();  
encryptor.setPassword("OrderMod");   
Properties props = new EncryptableProperties(encryptor); 
props.load(new FileInputStream("mime.properties")); 
String password = props.getProperty("password"); 
System.out.println("password:: "+password); 

回答

0

您可以設置在加密算法:

StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();  
encryptor.setPassword("OrderMod"); 
encryptor.setAlgorithm(jasyptAlgorithm); 
Properties props = new EncryptableProperties(encryptor); 

其中jasyptAlgorithm是要使用,像PBEWithMD5AndTripleDES較強的算法。 Jasypt實際上並沒有實現任何算法,因此您需要從JCE提供程序中找到算法列表,例如Oracle JCA(隨Oracle Java一起提供)或Bouncy Castle

如果您使用的是強大的算法(如3DES),您可能需要下載並安裝Java Cryptography Extension Unlimited Strength Jurisdiction Policy Files

你提到SHA-512,但這不是一個加密算法都沒有。它只是一個哈希算法。許多加密進程可能能夠使用SHA-512,但其他一些算法將處理加密。

相關問題