我写了个软件 有登陆功能 登陆的时候 是连接远程的MSSQL  如何对这软件加保护 不要轻易的被别人调试出 连接SQL的IP 帐号 和密码

解决方案 »

  1.   

    用ADO的話CONNECTION接受的是明文的密碼,基本上沒有什麼好的辦法。注意權限設置吧。
      

  2.   

    自己写一个加密传输算法吧,用MD5或者DES都行
      

  3.   

    最简单易行的是将字符串加密(不要使用明文)。其次设置数据库的特定用户/密码/权限,不要使用sa用户,sa用户的密码要足够复杂。最后是设置数据库的访问端口,不要使用默认的端口。以上几条全部做到后,你的保护体系就很出色了
      

  4.   


    unit Cl_crypt32;
    interfaceuses
      SysUtils;const
      StartKey = 820;   {Start default key}
      MultKey   = 58145; {Mult default key}
      AddKey   = 28564; {Add default key}function cl_encrypt(s:string):string;
    function cl_decrypt(s:string):string;implementation{$R-}
    {$Q-}
    {*******************************************************
     * Standard Encryption algorithm - Copied from Borland *
     *******************************************************}
    function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
    var
      I : Byte;
    begin
      Result := '';
      for I := 1 to Length(InString) do
      begin
        Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
        StartKey := (Byte(Result[I]) + StartKey) * MultKey + AddKey;
      end;
    end;
    {*******************************************************
     * Standard Decryption algorithm - Copied from Borland *
     *******************************************************}
    function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
    var
      I : Byte;
    begin
      Result := '';
      for I := 1 to Length(InString) do
      begin
        Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
        StartKey := (Byte(InString[I]) + StartKey) * MultKey + AddKey;
      end;
    end;
    {$R+}
    {$Q+}{Coded by cloudy}
    Function cl_intto0str(int1:integer; len:integer):string;
    var
       i,j:integer;
    begin
         if length(inttostr(int1))>=len then
            result:=inttostr(int1)
         else
            begin
                 result:='';
                 i:=len-length(inttostr(int1));
                 for j:=1 to i do result:=result+'0';
                 result:=result+inttostr(int1);
            end;
    end;{Coded by cloudy}
    function cl_chartobytestr(s:string):string;
    var
       i:byte;
    begin
         result:='';
         for i:=1 to length(s) do
             result:=result+cl_intto0str(byte(s[i]),3);
    end;function cl_bytetocharstr(s:string):string;
    var
       i:integer;
    begin
         i:=1;
         result:='';
         if (length(s) mod 3)=0 then
            while i<length(s) do
            begin
                result:=result+char(strtoint(copy(s,i,3)));
                i:=i+3;
            end;
    end;{Coded by cloudy}
    function cl_encrypt(s:string):string;
    var
       years, months, days, hours, mins, secs, msec:word;
       cl_StartKey, cl_MultKey, cl_AddKey: longint;begin
         decodedate(now, years, months, days);
         decodetime(now, hours, mins, secs, msec);
         cl_StartKey:=msec;
         if cl_StartKey<256 then cl_StartKey:=cl_StartKey+256;
         cl_Multkey:=((years-1900)*12+months)*30+days+cl_StartKey*10+cl_StartKey;
         cl_AddKey:=(23*hours+mins)*60+secs+cl_StartKey*10+cl_StartKey;
         result:=cl_chartobytestr(Encrypt(cl_intto0str(cl_StartKey,3),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_Multkey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_Addkey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(s,cl_StartKey,cl_MultKey,cl_AddKey));
    end;{Coded by cloudy}
    function cl_decrypt(s:string):string;
    var
       cl_StartKey, cl_Multkey, cl_AddKey:longint;
    begin
       cl_StartKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 1, 9)),StartKey,MultKey,AddKey));
       cl_MultKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 10, 15)),StartKey,MultKey,AddKey));
       cl_AddKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 25, 15)),StartKey,MultKey,AddKey));
       result:=decrypt(cl_bytetocharstr(copy(s, 40, length(s)-39)),cl_StartKey,cl_MultKey,cl_AddKey);
    end;
    end.
    保存为:Cl_crypt32.pas 
    然后引用,两个函数:cl_encrypt(s:string):string 加密
    cl_decrypt(s:string):string 解密。
      

  5.   

    谢谢你的代码    在软件里面用加密   那解密呢 防在服务器上?   我是租的SQL数据库 没办法放这东西的吧?
      

  6.   

    而且 ADO连接的时候 不用输入帐号密码 是直接在控件上已经设置好的吧
      

  7.   

    看看我那段代码,加密解密都在里面了。这个通常是在外部用ini或者xml配置服务器时用的。别人打开ini或者xml文件看到的是加密后的字符串,程序中使用时直接解密用即可。
      

  8.   

    mysterx 
    我理解你的意思是 用1个INI文件里保存加密后的文字 然后 程序启动后 自己调用INI中文字进行解密  我理解的对吗?  
      

  9.   

    还有个问题是 xml配置服务器 是什么文件 我没看见过
      

  10.   

    这样写对吗
    我在要连接服务器的时候先  ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='+quotedstr(cl_decrypt(Label10.Caption))+';Persist Security Info=True;User ID='+quotedstr(cl_decrypt(Label9.Caption))+';Initial Catalog=sq_zhiyin;Data Source= '+quotedstr(cl_decrypt(Label8.Caption));这样是不是 IP 帐号 密码 就不文明了?
    如果是的话 那用截包软件 截取连接时候的封包 会是怎么样的呢