用VFP写的加密函数
*FunCtion CalcPassWord
Para Lczip,Lcpass    lCPASS=Allt(Lcpass)
IF LcZip      &&加密
    Lcpass="DALY"+Lcpass
    LCNewPass=CHR(Len(Lcpass))     *处理字符串,使它不为空。因为我要把加密后的字符放到数据库,为防他人直接打开数据库看出密码为空。
  For i=1 To Len(Lcpass)
        LCNewPass=LCNewPass+Chr(asc(SubStr(Lcpass,i,1))/32);
                +Chr(asc(SubStr(Lcpass,i,1))%32)  EndFor
  *取出字符串中的单个字符,并把它转为ASCII码。  *把ASCII码除于32得到的整数跟余数转为字符,再把两个字符和合为一个字符串  *经这种处理后,已经无法得知原来的字符,只有经计算机用反方法解开。
  LCNewPass=PADR(LCNewPass,50,CHR(1))  &&返回50个字符长度,不足的用CHR(1)补足。
Else
    IF LEN(lCPASS)#50       &&如果长度出错,证明非法修改过
        =MESSAGEbOX("密码被非法修改",0,_screen.caption)
        Return "ERROR"
    ENDIF
    For i=1 TO 50
       IF asc(SubStr(Lcpass,i,1))>=32  &&检查密码是否被非法修改
           =MESSAGEbOX("密码被非法修改",0,_screen.caption)
           Return "ERROR"
       ENDIF
    EndFor
    LCNewPass=""  &&解密
    For I=0 TO (asc(SubStr(Lcpass,1,1))*2)-9
        LCNewPass=LCNewPass+Chr(asc(SubStr(Lcpass,i+10,1))*32;
             +asc(SubStr(Lcpass,i+11,1)))
        i=i+1 
    EndFor
EndIF
Return LcNewPass把上面的加密函数转化为ASP是这样的
<%
Function lcpass_CREATE(Lcpass)
Lcpass="DALY"&Lcpass
LCNewPass=CHR(Len(Lcpass))
For i=1 To Len(Lcpass)
    'response.write cstr(cint(asc(mid(Lcpass,i,1)))\32)&"-"&cstr(asc(mid(Lcpass,i,1)))&"-"
    'response.write cstr(cint(asc(mid(Lcpass,i,1))) mod 32)
    'response.write "<br>"
    LCNewPass=LCNewPass&Chr(cint(asc(mid(Lcpass,i,1)))\32)&Chr(cint(asc(mid(Lcpass,i,1))) mod  32)nextstr=String(50,CHR(1)) LCNewPass=left(LCNewPass&str,50)
lcpass_CREATE=LCNewPass
end Function 
%>那么怎么转化为JAVA版的呢???

解决方案 »

  1.   

    第一句就没看懂 :(lCPASS=Allt(Lcpass)
      

  2.   

    http://www.9ijz.com/info.php?name=summaryyhg
    这里可以看到

    public class MD5Encode 
    {    private static final String hexDigits[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", 
             "c", "b", "a", "d", "f", "e"
         };
    public static String byteArrayToHexString(byte b[])
    {
    StringBuffer resultSb = new StringBuffer();
    for(int i = 0; i < b.length; i++)
    {
    resultSb.append(byteToHexString(b[i]));
    }
    return resultSb.toString();
    } private static String byteToHexString(byte b)
    {
    int n = b;
    if(n < 0)
    {
    n = 256 + n;
    }
    int d1 = n / 16;
    int d2 = n % 16;
    return hexDigits[d1] + hexDigits[d2];
    } public String MD5Encode(String origin)
    {
    String resultString = null;
    try
    {
    resultString = new String(origin);
    MessageDigest md = MessageDigest.getInstance("MD5");

    resultString = byteArrayToHexString(md.digest(resultString.getBytes()));
    }
    catch(Exception ex)
    {

    }
    return resultString;
    }}