admin管理员组

文章数量:1576349

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))));

}

}

本文标签: 可逆测试加密算法函数