C#使用SafeNet的開發狗和超級狗加密使用方法

1.在安裝光盤中選擇Windows文件夾,單擊Setup.exe執行安裝程序,安裝過程默認選擇,單擊下一步即可。
2.安裝完畢後插入超級狗,在菜單欄中打開“超級狗開發商嚮導”,選擇下載API,然後默認選擇下一步,下載完成後會提示下載全部成功
,此時超級狗中需要導入的資源文件都已成功完成,並且在c盤指定安裝路徑下生成了新的hvc文件(VendorCodes文件夾中)、dog_windows_xxxxx.dll和
dog_windows_x64_xxxxx.dll文件(xxxxx爲隨機數字,Tools/makekeys文件夾中)
3.在程序中使用License API加密方法
   (1)插入子狗(小U盤)
   (2)找到api_dsp_windows.dll,api_dsp_windows_x64.dll,dog_net_windows.dll,dog_windows_3154506.dll(數字爲開發號)
       ,dog_windows_x64_3154506.dll這5個庫文件(前三個文件默認路徑在C:\Program Files(x86)\Gemalto\SuperDog\2.1\API\Licensing\.net中),並復
         制到需要加密程序的bin目錄下,後兩個文件在C:\Program Files(x86)\Gemalto\SuperDog\2.1\Tools\makekeys文件夾中
   (3)打開需要加密的程序,引用dog_net_windows.dll文件。


   (4)在路徑爲C:\Program Files(x86)\Gemalto\SuperDog\2.1\VendorCodes的hvc文件中獲取供應商代碼,放到程序中。
   使用源碼實例

           string scope = "<dogscope />";
           string strVendorCode="xxx";//VendorCodes的hvc文件中的字符串,每個開發狗更新時都會改變售號代碼
           DogStatus status;              
            DogFeature feature = DogFeature.Default;
            Dog curDog = new Dog(feature);
           status = curDog.Login(strVendorCode, scope);//只要終端的超級狗授權到期會提示非ok的其他狀態
            if (status != DogStatus.StatusOk)
            {
                if (status == DogStatus.InvalidVendorCode)
                {
                    Console.WriteLine("Invalid vendor code.\n");
                }
                else if (status == DogStatus.UnknownVcode)
                {
                    Console.WriteLine("Vendor Code not recognized by API.\n");
                }
                else
                {
                    Console.WriteLine("Login to feature failed with status: " + status);
                }
                return status;
            }
            else
           {
                 Console.WriteLine(status.ToString() +"登陸加密狗成功");

                DateTime time = DateTime.Now;
                status = curDog.GetTime(ref time);

                GetInfoDemo();//獲取加密類型

                string info = null;
                status = curDog.GetSessionInfo(Dog.KeyInfo,ref info);//獲取節點信息

                byte[] bufData = new byte[128];
                status = curDog.Decrypt(bufData);
                if (DogStatus.StatusOk != status)
                {
                    Console.WriteLine("Dog decrypt failed with status: " + status);
                    curDog.Logout();
                    return status;
                }
               string strContents = UTF8Encoding.UTF8.GetString(bufData,0,15);

                DogFile dogFile= curDog.GetFile();
                 dogFile.Read(ref strContents);
                strContents = strContents.Substring(0,strContents.IndexOf("1857")+4);
                int length = strContents.Length;

                return status;

            }
         //獲取超級狗節點信息
           protected void GetInfoDemo()
             {
            string queryFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
                                                      "<dogformat root=\"dog_info\">" +
                                                        " <feature>" +
                                                        "  <attribute name=\"id\" />" +
                                                        "  <element name=\"license\" />" +
                                                        " </feature>" +
                                                        "</dogformat>";
        
            string info = null;

            DogStatus status = Dog.GetInfo(scope, queryFormat, VendorCode.strVendorCode, ref info);

    
                   }

//只有插入開發狗,才能設計不同的自定義“超級狗許可文件.xml”,如果開發狗和超級狗都在一塊,則同時插入pc中進行許可設計然後編程超級狗就可以。
//如果軟件開發商只有開發狗,而客戶手裏有超級狗,則更新license的時候就需要:讓客戶安裝超級狗組件,在組件的工具軟件中選擇遠程升級工具,生成
超級狗的請求文件(.c2v);軟件開發商拿到這個客戶給的許可請求文件後插入開發狗,在超級狗設計許可工具中設計許可方式並生成許可升級文件(.v2c);
然後軟件開發商將許可升級文件發送給客戶,客戶拿到許可升級文件在遠程升級工具裏導入升級即可。
//注意:每個超級狗生成許可請求文件再發給軟件開發商生成許可升級文件後,客戶只允許一次升級,之後文件就會失效,所以每次升級都要重新執行以上的操作
(請求文件重新生成)
//如果首次運行超級狗遠程升級工具失敗,則需要在“遠程升級界面定製工具(默認的RUS.exe)”中重新生成一個RUS.exe,然後運行該.exe文件替代原有的.exe。


//代碼編譯完畢後無需更改,只要終端的超級狗授權到期會提示非ok的其他狀態


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章