admin管理员组文章数量:1652184
2023年12月17日发(作者:)
简单MD5类
import eDigest;public class MD5Demo {
public static class MD5_test {
public final static String MD5(String s) {
char hexDigits[] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' ,
'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
try {
byte [] strTemp = es();
MessageDigest mdTemp = tance("MD5" );
(strTemp);
byte [] md = ();
int j = ;
char str[] = new char [j * 2 ];
int k = 0 ;
for ( int i = 0 ; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf ];
str[k++] = hexDigits[byte0 & 0xf ];
}
return new String(str);
} catch (Exception e) {
return null ;
}
}
public static void main(String[] args) {
// MD5_test aa = new MD5_test();
(MD5_5("b" ));
}
}
}加密----------解密 MD5类import eDigest;
public class MD5andKL {
// MD5加码。32位
public static String MD5(String inStr) {
MessageDigest md5 = null;
try {
md5 = tance("MD5");
} catch (Exception e) {
n(ng());
tackTrace();
return "";
}
char[] charArray = Array();
byte[] byteArray = new byte[];
for (int i = 0; i < ; i++)
byteArray[i] = (byte) charArray[i];
byte[] md5Bytes = (byteArray);
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < ; i++) {
int val = ((int) md5Bytes[i]) & 0xff;
if (val < 16)
("0");
(tring(val));
}
return ng();
}
// 可逆的加密算法
public static String KL(String inStr) {
// String s = new String(inStr);
char[] a = Array();
for (int i = 0; i < ; i++) {
a[i] = (char) (a[i] ^ 't');
}
String s = new String(a);
return s;
}
// 加密后解密
public static String JM(String inStr) {
char[] a = Array();
for (int i = 0; i < ; i++) {
a[i] = (char) (a[i] ^ 't');
}
String k = new String(a);
return k;
}
// 测试主函数
public static void main(String args[]) {
String s = new String("a");
n("原始:" + s);
n("MD5后:" + MD5(s));
n("MD5后再加密:" + KL(MD5(s)));
n("解密为MD5后的:" + JM(KL(MD5(s))));
}
}
版权声明:本文标题:Java的MD5加密和解密类 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1702807509a25284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论