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的其他状态


 

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