java中加密和解密之二

public static String decryptDES(String sInfo)
{
// 定义解密算法
String Algorithm = "DES";
// 生成解密key
Key key = getKey();
String rs = "";
byte[] cipherByte = null;
try
{
// 得到加密、解密器
Cipher cl = Cipher.getInstance(Algorithm);
// 用指定的密钥和模式初始化Cipher对象
cl.init(Cipher.DECRYPT_MODE, key);
// 对要解密的内容进行解密
cipherByte = cl.doFinal(hex2byte(sInfo));
rs = new String(cipherByte);
}
catch (Exception e)
{
logger.error(e.getMessage(), e);
}
return rs;
}


/**
* 十六进制字符串转化为2进制
*
* @param hex
* @return
*/
public static byte[] hex2byte(String strIn)
{
byte[] arrB = strIn.getBytes();
int iLen = arrB.length;
// 两个字符表示一个字节,所以字节数组长度是字符串长度除以2
byte[] arrOut = new byte[iLen / 2];
for (int i = 0; i < iLen; i = i + 2)
{
String strTmp = new String(arrB, i, 2);
arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
}
return arrOut;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值