双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

加密 总结

heliit heliit 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
/**
* MD5加密
*
* @param pwd
* 传入的密码字符串
* @return 加密后的密码
* @see [类、类#方法、类#成员]
*/
public static String getMD5pwd(String pwd) {
StringBuffer code = new StringBuffer("");
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(pwd.getBytes());
byte[] bt = md.digest();
int j;
for (int i = 0; i < bt.length; i++) {
j = bt[i];
if (j < 0) {
j += 256;
}
if (j < 16) {
code.append("0");
}
code.append(Integer.toHexString(j));
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return code.toString();
}

/**
* 获取系统密钥
* @return 系统默认密钥
* @see [类、类#方法、类#成员]
*/
public static String getSystemKey(){
SysConfigManager sysConfigManager = DBGroup.getInstance().getVGroup().getSystemGroup().getSysConfigManager();
SysConfig key_sysConfig = sysConfigManager.findSysConfigByCode("system_key");
return key_sysConfig.getConfigValue();
}

/**
* Des解密
*
* @param pwd
* 密码
* @return 解密后的密码
* @see [类、类#方法、类#成员]
*/
public static String DesDecode(String pwd,String desSceret) {
// 为我们选择的DES算法生成一个KeyGenerator对象
try {
Key key = init("DESede",desSceret);
Cipher cipher = Cipher.getInstance("DESede");
// 解密
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] tt = cipher.doFinal(hex2byte(pwd));
String code = new String(tt);
return code;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

/**
* 创建密匙
* @param algorithm 加密算法,可用 DES,DESede,Blowfish
* @param desSceret 加密密钥,要求转换为UTF-8的格式,字节长度至少24位
* @return 秘密(对称)密钥
* @see [类、类#方法、类#成员]
*/
private static Key init(String algorithm, String desSceret) {
Key key = null;
try {
DESedeKeySpec dks = new DESedeKeySpec(desSceret
.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory
.getInstance(algorithm);
key = keyFactory.generateSecret(dks);
} catch (Exception e) {
e.printStackTrace();
}
return key;
}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
heliit
Java EE 67,535 成员 225,843 内容