没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
java字符串加密解密
try {
String test = "123456789@fdj.com";
EncryptionDecryption des = new EncryptionDecryption("tourhb");// 自定义密钥
System.out.println("加密前的字符:" + test);
System.out.println("加密后的字符:" + des.encrypt(test));
System.out.println("解密后的字符:" + des.decrypt(des.encrypt(test)));
System.out.println("解密后的字符:"
+ des.decrypt("fe14c7c41f7d2a94b07d7928b21346e7"));
} catch (Exception e) {
e.printStackTrace();
}
下面是加密解密类的源码
import java.security.Key;
import java.security.Security;
import javax.crypto.Cipher;
public class EncryptionDecryption {
private static String strDefaultKey = "tourhb";
/** 加密工具 */
private Cipher encryptCipher = null;
try {
String test = "123456789@fdj.com";
EncryptionDecryption des = new EncryptionDecryption("tourhb");// 自定义密钥
System.out.println("加密前的字符:" + test);
System.out.println("加密后的字符:" + des.encrypt(test));
System.out.println("解密后的字符:" + des.decrypt(des.encrypt(test)));
System.out.println("解密后的字符:"
+ des.decrypt("fe14c7c41f7d2a94b07d7928b21346e7"));
} catch (Exception e) {
e.printStackTrace();
}
下面是加密解密类的源码
import java.security.Key;
import java.security.Security;
import javax.crypto.Cipher;
public class EncryptionDecryption {
private static String strDefaultKey = "tourhb";
/** 加密工具 */
private Cipher encryptCipher = null;
/** 解密工具 */
private Cipher decryptCipher = null;
/**
* 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813, 和public static byte[]
* hexStr2ByteArr(String strIn) 互为可逆的转换过程
*
* @param arrB
* 需要转换的byte数组
* @return 转换后的字符串
* @throws Exception
*
*/
public static String byteArr2HexStr(byte[] arrB) throws Exception {
int iLen = arrB.length;
// 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
StringBuffer sb = new StringBuffer(iLen * 2);
for (int i = 0; i < iLen; i++) {
int intTmp = arrB[i];
// 把负数转换为正数
while (intTmp < 0) {
intTmp = intTmp + 256;
}
// 小于0F的数需要在前面补0
if (intTmp < 16) {
sb.append("0");
}
sb.append(Integer.toString(intTmp, 16));
}
return sb.toString();
private Cipher decryptCipher = null;
/**
* 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813, 和public static byte[]
* hexStr2ByteArr(String strIn) 互为可逆的转换过程
*
* @param arrB
* 需要转换的byte数组
* @return 转换后的字符串
* @throws Exception
*
*/
public static String byteArr2HexStr(byte[] arrB) throws Exception {
int iLen = arrB.length;
// 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
StringBuffer sb = new StringBuffer(iLen * 2);
for (int i = 0; i < iLen; i++) {
int intTmp = arrB[i];
// 把负数转换为正数
while (intTmp < 0) {
intTmp = intTmp + 256;
}
// 小于0F的数需要在前面补0
if (intTmp < 16) {
sb.append("0");
}
sb.append(Integer.toString(intTmp, 16));
}
return sb.toString();
剩余6页未读,继续阅读
yjflinchong
- 粉丝: 671
- 资源: 210
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页