using Microsoft.Win32;

 

//加密

        private string Encrypt(string Org,string key)

        {

            string res = "";

 

 

                try {

                    //加上該電腦的ProductID,通常可以省略,不一定要加

key += Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Registration", false).GetValue("ProductId").ToString();

                    if (Org.Length == 0)

                        res = "";

                    for (int i = 0; i < Org.Length; i++)

                    {

                        res += (Char)((int)Org[i] ^ ((int)key[i % key.Length]));

                    }

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.Message);

                }

            return res;

        }

 

 

//解密

        private string Decrypt(string Ans,string key)

        {

            return Encrypt(Ans,key);

        }

 

 

 


 

 //讀取登錄檔  

                RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Software\connStr", false);

                string strEncryptedString = (string)rk.GetValue("connStr");

 

//寫入登錄檔

                RegistryKey rk = Registry.LocalMachine;

                rk = rk.CreateSubKey(@"Software\connStr");

                rk.SetValue("connStr", txtAns.Text);


ASP版

 

<% 

response.write "加密字串為:"&GetConStr() &"<br/>"

response.write "解密字串為:"&Decrypt(GetConStr(),"111")

 

Function GetConStr()

           Dim ReadConnStr

           Set ReadConnStr=CreateObject("WScript.Shell")

           GetConStr=ReadConnStr.RegRead("HKLM\Software\connStr\connStr")

End Function

 

Function Encrypt(ecode,key)

           Dim ReadCompID

           Set ReadCompID=CreateObject("WScript.Shell")

           key = key & ReadCompID.RegRead("HKLM\SOFTWARE\Microsoft\Internet Explorer\Registration\ProductId")                  

           For i = 0 to Len(ecode) -1

                     strEncrypted = strEncrypted & Chr(Asc(mid(ecode,i+1,1)) Xor Asc(mid(key,(i Mod Len(key))+1,1)))

           Next

           Encrypt = strEncrypted

End Function

 

Function Decrypt(dcode,key)

           Decrypt=Encrypt(dcode,key)

End function

%>

 

 

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 ikaritw 的頭像
    ikaritw

    嚼的絮絮叨叨

    ikaritw 發表在 痞客邦 留言(0) 人氣()