資源簡介
DES、AES對稱加密算法,之前從網上找的,但是在MAC上運行發現每次加密出來的結果都不一樣,后來查了一些博客,最后確認是SecureRandom的隨機算法問題,需要設置setSeed.
代碼片段和文件信息
package?com.cloudcc.util;
import?java.security.InvalidKeyException;
import?java.security.Key;
import?java.security.NoSuchAlgorithmException;
import?java.security.SecureRandom;
import?java.util.PropertyResourceBundle;
import?java.util.ResourceBundle;
import?javax.crypto.Cipher;
import?javax.crypto.KeyGenerator;
import?javax.crypto.NoSuchPaddingException;
import?sun.misc.base64Decoder;
import?sun.misc.base64Encoder;
public?class?DesEncoder?{
static?DesEncoder?instance;
????static?Key?key;
????static?ResourceBundle?prb?=?PropertyResourceBundle.getBundle(“conf“);//?獲取配置文件
????static?Cipher?encryptCipher;
????static?Cipher?decryptCipher;
????static?String?maskcode?=?prb.getString(“maskcode“);//?獲取秘鑰
????public?DesEncoder()?{
????}
?
????protected?DesEncoder(String?strKey)?{
????????key?=?s
評論
共有 條評論