public class Test2 { public static String encryptStr(String decryptpasswd) {
char key1 = '+', key2 = '@';
int i = 0, j = 0, decryptpasswdlength = 0;
char[] tmpstr = new char[128];
String encryptpasswd = null;
if ((decryptpasswd == null) || (decryptpasswdlength = decryptpasswd.length()) == 0){
return(encryptpasswd);
}
i = 0;
while (decryptpasswd.charAt(i) == ' ') i++;
if (i >= decryptpasswdlength){
return(encryptpasswd);
}
j = decryptpasswdlength-1;
for (i = 0; i < decryptpasswdlength; i+=2){
tmpstr[j] = (char)(decryptpasswd.charAt(i) << ((j+1)%7));
tmpstr[j] = (char)(tmpstr[j] | key1);
tmpstr[j] = (char)(tmpstr[j] & 0x00FF);
j--;
}
for (i = 1; i < decryptpasswdlength; i+=2){
tmpstr[j] = (char)(decryptpasswd.charAt(i) << ((j+2)%7));
tmpstr[j] = (char)(tmpstr[j] | key2);
tmpstr[j] = (char)(tmpstr[j] & 0x00FF);
j--;
}
for (i = 0; i < decryptpasswdlength; i++){
if (tmpstr[i] == ' ')
tmpstr[i] = '^';
}
encryptpasswd = String.copyValueOf(tmpstr,0,decryptpasswdlength);
return(encryptpasswd);
}
public static void main(String[] args) {
Test2 test2 = new Test2();
String str1 = Test2.encryptStr("11111");
System.out.println(str1);//???;+
String str2 = "???;+";
System.out.println(str1.equals(str2));
//以上现象导致的结果是 sql语句打印出来:select * from app_employee where userid='test1'and password='???;+'
//再plsql 中能执行出来结果,但是select * from app_employee where userid='test1'and password='???;+',数据库中有数据单查询不出结果
//原因:上述两个字符串为什么不相同,
}
}///////////////////////////////////////现在很苦恼 查询不出结果就取不出用户信息,各位大侠帮帮我一下吧!
谢谢
能不能给我说一下原理呢?感激不尽
关键在于String的方法
1 getBytes() 使用平台的默认字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。
2getBytes(String charsetName) 使用指定的字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。你用encryptpasswd.getBytes("GBK")吧。因为我的平台是gbk的。所以encryptpasswd.getBytes(),和encryptpasswd.getBytes("GBK")效果一样。也就是说你上面最后返回的return(encryptpasswd);中的encryptpasswd是字符串"???;+"经过GBK编码后得到的,所以要用getBytes("GBK")转化成字符串"???;+"
说实话 我工作一年了 头会看到 return语句这么写的
编码就能工作了.
这个是一个密码加密程序???也太简单了点吧!