无为清净楼资源网 Design By www.qnjia.com
1、md5加密,该加密算法是单向加密,即加密的数据不能再通过解密还原。相关类包含在java.security.MessageDigest包中。
2、3-DES加密,该加密算法是可逆的,解密方可以通过与加密方约定的密钥匙进行解密。相关类包含在javax.crypto.*包中。
3、base64编码,是用于传输8bit字节代码最常用的编码方式。相关类在sun.misc.BASE64Decoder 和sun.misc.BASE64Encoder 中。
4、URLEncoder编码,是一种字符编码,保证被传送的参数由遵循规范的文本组成。相关类在java.net.URLEncoder包中。
细节:
1、进行MD5加密,得到byte[]
复制代码 代码如下:
/**
* 进行MD5加密
* @param String 原始的SPKEY
* @return byte[] 指定加密方式为md5后的byte[]
*/
private byte[] md5(String strSrc)
{
byte[] returnByte = null;
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
returnByte = md5.digest(strSrc.getBytes("GBK"));
}
catch(Exception e)
{
e.printStackTrace();
}
return returnByte;
}
2、得到3-DES的密钥匙
复制代码 代码如下:
/**
* 得到3-DES的密钥匙
* 根据根据需要,如密钥匙为24个字节,md5加密出来的是16个字节,因此后面补8个字节的0
* @param String 原始的SPKEY
* @return byte[] 指定加密方式为md5后的byte[]
*/
private byte[] getEnKey(String spKey)
{
byte[] desKey=null;
try
{
byte[] desKey1 = md5(spKey);
desKey = new byte[24];
int i = 0;
while (i < desKey1.length && i < 24) {
desKey[i] = desKey1[i];
i++;
}
if (i < 24) {
desKey[i] = 0;
i++;
}
}
catch(Exception e){
e.printStackTrace();
}
return desKey;
}
3、3-DES加密
复制代码 代码如下:
/**
* 3-DES加密
* @param byte[] src 要进行3-DES加密的byte[]
* @param byte[] enKey 3-DES加密密钥
* @return byte[] 3-DES加密后的byte[]
*/
public byte[] Encrypt(byte[] src,byte[] enKey)
{
byte[] encryptedData = null;
try
{
DESedeKeySpec dks = new DESedeKeySpec(enKey);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);
encryptedData = cipher.doFinal(src);
}
catch(Exception e)
{
e.printStackTrace();
}
return encryptedData;
}
4、对字符串进行Base64编码
复制代码 代码如下:
/**
* 对字符串进行Base64编码
* @param byte[] src 要进行编码的字符
*
* @return String 进行编码后的字符串
*/
public String getBase64Encode(byte[] src)
{
String requestValue="";
try{
BASE64Encoder base64en = new BASE64Encoder();
requestValue=base64en.encode(src);
//System.out.println(requestValue);
}
catch(Exception e){
e.printStackTrace();
}
return requestValue;
}
12下一页阅读全文
2、3-DES加密,该加密算法是可逆的,解密方可以通过与加密方约定的密钥匙进行解密。相关类包含在javax.crypto.*包中。
3、base64编码,是用于传输8bit字节代码最常用的编码方式。相关类在sun.misc.BASE64Decoder 和sun.misc.BASE64Encoder 中。
4、URLEncoder编码,是一种字符编码,保证被传送的参数由遵循规范的文本组成。相关类在java.net.URLEncoder包中。
细节:
1、进行MD5加密,得到byte[]
复制代码 代码如下:
/**
* 进行MD5加密
* @param String 原始的SPKEY
* @return byte[] 指定加密方式为md5后的byte[]
*/
private byte[] md5(String strSrc)
{
byte[] returnByte = null;
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
returnByte = md5.digest(strSrc.getBytes("GBK"));
}
catch(Exception e)
{
e.printStackTrace();
}
return returnByte;
}
2、得到3-DES的密钥匙
复制代码 代码如下:
/**
* 得到3-DES的密钥匙
* 根据根据需要,如密钥匙为24个字节,md5加密出来的是16个字节,因此后面补8个字节的0
* @param String 原始的SPKEY
* @return byte[] 指定加密方式为md5后的byte[]
*/
private byte[] getEnKey(String spKey)
{
byte[] desKey=null;
try
{
byte[] desKey1 = md5(spKey);
desKey = new byte[24];
int i = 0;
while (i < desKey1.length && i < 24) {
desKey[i] = desKey1[i];
i++;
}
if (i < 24) {
desKey[i] = 0;
i++;
}
}
catch(Exception e){
e.printStackTrace();
}
return desKey;
}
3、3-DES加密
复制代码 代码如下:
/**
* 3-DES加密
* @param byte[] src 要进行3-DES加密的byte[]
* @param byte[] enKey 3-DES加密密钥
* @return byte[] 3-DES加密后的byte[]
*/
public byte[] Encrypt(byte[] src,byte[] enKey)
{
byte[] encryptedData = null;
try
{
DESedeKeySpec dks = new DESedeKeySpec(enKey);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);
encryptedData = cipher.doFinal(src);
}
catch(Exception e)
{
e.printStackTrace();
}
return encryptedData;
}
4、对字符串进行Base64编码
复制代码 代码如下:
/**
* 对字符串进行Base64编码
* @param byte[] src 要进行编码的字符
*
* @return String 进行编码后的字符串
*/
public String getBase64Encode(byte[] src)
{
String requestValue="";
try{
BASE64Encoder base64en = new BASE64Encoder();
requestValue=base64en.encode(src);
//System.out.println(requestValue);
}
catch(Exception e){
e.printStackTrace();
}
return requestValue;
}
12下一页阅读全文
标签:
java,MD5加密
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《神话时代:重述版》评测:粉丝们的朝花夕拾
- 战锤40K星际战士2先锋职业介绍|先锋职业技能效果一览
- 战锤40K星际战士2重装职业介绍|重装职业技能效果一览
- 交错战线能源发电站推荐角色一览
- 阿波罗乐神之音《第4集出埃及记》[WAV+CUE]
- JohnWrightTrio-SouthSideSoul-1960-2024(24-192)
- AnthonyBruno-Cefalu(2024)[24-96]
- 《地狱潜者2》玩家人数飙升:终于不再削弱玩家了
- 黑神话引力!外媒分享孙悟空英文书籍:美生中国人等
- 《荒野大镖客》PC版曝光!《GTA6》疑似也有PC版
- 林宥嘉.2008-神秘嘉宾(引进版)【华研国际】【WAV+CUE】
- 徐小凤.1997-金曲精选(康艺经典珍藏系列)【康艺成音】【WAV+CUE】
- 群星.1994-非常精丫宝丽金】【WAV+CUE】
- 《赛马娘 热血喧闹大感谢祭!》评测:现代复古派对
- 《星球大战:亡命之徒》评测:还是看看远方的光剑吧