コード例 #1
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to perform a login and a logout
        /// using the default feature.
        /// </summary>
        protected void LoginLogoutDefaultDemo()
        {
            Verbose("Login/Logout Demo with Default Feature (DogFeature.Default)");

            DogFeature feature = DogFeature.Default;

            Verbose("Login:"******"Logout:");
                status = dog.Logout();

                ReportStatus(status);
            }

            // recommended, but not mandatory
            // this call ensures that all resources to SuperDog
            // are freed immediately.
            dog.Dispose();
            Verbose("");
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: qwdingyu/C-
        private void button2_Click(object sender, EventArgs e)
        {
            DogFeature feature = DogFeature.Default;

            using (Dog dog = new Dog(feature))
            {
                DogStatus status = dog.Login(VendorCode.Code, scope);
                if ((null == dog) || !dog.IsLoggedIn())
                {
                    return;
                }
                DogFile file = dog.GetFile(FileId);
                if (!file.IsLoggedIn())
                {
                    // Not logged into a dog - nothing left to do.
                    return;
                }
                int size = 0;
                status = file.FileSize(ref size);
                if (DogStatus.StatusOk != status)
                {
                    return;
                }

                // read the contents of the file into a buffer
                byte[] bytes = new byte[size];
                status = file.Read(bytes, 0, bytes.Length);
                if (DogStatus.StatusOk != status)
                {
                    return;
                }
                this.textBox4.Text = System.Text.Encoding.UTF8.GetString(bytes);
            }
        }
コード例 #3
0
ファイル: DogHelper.cs プロジェクト: qwdingyu/C-
        public static string ReadData()
        {
            DogFeature feature = DogFeature.Default;

            using (Dog dog = new Dog(feature))
            {
                DogStatus status = dog.Login(VendorCode.Code, scope);
                if ((null == dog) || !dog.IsLoggedIn())
                {
                    return("请插入加密狗");
                }
                DogFile file = dog.GetFile(FileId);
                if (!file.IsLoggedIn())
                {
                    // Not logged into a dog - nothing left to do.
                    return("加载数据失败");
                }
                int size = 0;
                status = file.FileSize(ref size);
                if (DogStatus.StatusOk != status)
                {
                    return("加载数据失败");
                }

                // read the contents of the file into a buffer
                byte[] bytes = new byte[size];
                status = file.Read(bytes, 0, bytes.Length);
                if (DogStatus.StatusOk != status)
                {
                    return("失败");
                }
                return(System.Text.Encoding.UTF8.GetString(bytes));
            }
        }
コード例 #4
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to perform a login using the default
        /// feature and how to perform an automatic logout
        /// using the SuperDog's Dispose method.
        /// </summary>
        protected void LoginDisposeDemo()
        {
            DogFeature feature = DogFeature.Default;
            Dog        dog     = new Dog(feature);
            DogStatus  status  = dog.Login(VendorCode.Code, scope);

            dog.Dispose();
        }
コード例 #5
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to login using a feature id.
        /// </summary>
        protected Dog LoginDemo(DogFeature feature)
        {
            // create a dog object using a feature
            // and perform a login using the vendor code.
            Dog       dog    = new Dog(feature);
            DogStatus status = dog.Login(VendorCode.Code, scope);

            return(dog.IsLoggedIn() ? dog : null);
        }
コード例 #6
0
ファイル: sample.cs プロジェクト: xrfmail/GitHub
        public DogStatus DecryptConst()
        {
            DogStatus status;
            UInt32    i = 0;

            byte[] bufData;

            Dog curDog = new Dog(new DogFeature(DogFeature.FromFeature(EncryptedConst1.EncryptConstFeatureID).Feature));

            /************************************************************************
             * Login
             *   establishes a context for SuperDog
             */
            status = curDog.Login(VendorCode.strVendorCode, scope);
            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);
            }

            bufData = new byte[EncryptedConst1.EncryptConstBufSize];
            for (i = 0; i < EncryptedConst1.EncryptConstBufSize; ++i)
            {
                bufData[i] = encrConst1.encryptConstArr[i];
            }

            // decrypt the data.
            // on success we convert the data back into a
            // human readable string.
            status = curDog.Decrypt(bufData);
            if (DogStatus.StatusOk != status)
            {
                Console.WriteLine("Dog decrypt failed with status: " + status);
                curDog.Logout();
                return(status);
            }

            //Use the decrypted constants do some operation
            encrConst1.ConstValue = encrConst1.ConvertByteArr(bufData);
            Console.WriteLine("The decrypted value is: " + encrConst1.ConstValue + ".");

            status = curDog.Logout();
            return(status);
        }
コード例 #7
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to perform a login and an automatic
        /// logout using C#'s scope clause.
        /// </summary>
        protected void LoginDefaultAutoDemo()
        {
            DogFeature feature = DogFeature.Default;

            // this will perform a logout and object disposal
            // when the using scope is left.
            using (Dog dog = new Dog(feature))
            {
                DogStatus status = dog.Login(VendorCode.Code, scope);
                Console.WriteLine("test");
            }
        }
コード例 #8
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Runs the API demo.
        /// </summary>
        public void RunDemo(string scope)
        {
            try
            {
                this.scope = scope;

                Header();

                // Demonstrate the different login methods
                LoginDefaultAutoDemo();
                LoginLogoutDefaultDemo();
                LoginDisposeDemo();

                // Demonstrates how to get a list of available features
                GetInfoDemo();

                // run the API demo using the default feature
                // (ALWAYS present in every SuperDog)
                Dog dog = LoginDefaultDemo();
                SessionInfoDemo(dog);
                ReadWriteDemo(dog, FileId);
                ReadWritePosDemo(dog, FileId);
                EncryptDecryptDemo(dog);
                TestTimeDemo(dog);
                LogoutDemo(ref dog);

                // run the API demo using feature id 42
                dog = LoginDemo(new DogFeature(DogFeature.FromFeature(42).Feature));
                SessionInfoDemo(dog);
                ReadWriteDemo(dog, FileId);
                ReadWritePosDemo(dog, FileId);
                EncryptDecryptDemo(dog);
                TestTimeDemo(dog);
                LogoutDemo(ref dog);

                Footer();
            }
            catch (Exception ex)
            {
                if (textHistory == null)
                {
                    Console.WriteLine(ex.Message);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message,
                                                         "Exception",
                                                         System.Windows.Forms.MessageBoxButtons.OK);
                }
            }
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: qwdingyu/C-
        private void button1_Click(object sender, EventArgs e)
        {
            DogFeature feature = DogFeature.Default;

            using (Dog dog = new Dog(feature))
            {
                DogStatus status = dog.Login(VendorCode.Code, scope);
                if ((null == dog) || !dog.IsLoggedIn())
                {
                    return;
                }
                DogFile file = dog.GetFile(FileId);
                if (!file.IsLoggedIn())
                {
                    // Not logged into a dog - nothing left to do.
                    return;
                }
                int size = 0;
                status = file.FileSize(ref size);
                if (DogStatus.StatusOk != status)
                {
                    return;
                }

                byte[] newBytes = System.Text.Encoding.UTF8.GetBytes(this.textBox1.Text);//new byte[] { 1, 2, 3, 4, 5, 6, 7 };

                status = file.Write(newBytes, 0, newBytes.Length);
                if (DogStatus.StatusOk != status)
                {
                    return;
                }



                // read the contents of the file into a buffer
                byte[] bytes = new byte[size];
                status = file.Read(bytes, 0, bytes.Length);
                if (DogStatus.StatusOk != status)
                {
                    return;
                }
                this.textBox2.Text = System.Text.Encoding.UTF8.GetString(bytes);
            }
            //textBox3.Text = dapi.WriteData(this.textBox1.Text.Trim());
            //this.textBox2.Text = dapi.ReadDate();
            //textBox3.SelectionStart = textBox3.TextLength;
            //textBox3.ScrollToCaret();
            //textBox3.Refresh();
        }
コード例 #10
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to login into a dog using the
        /// default feature. The default feature is ALWAYS
        /// available in every SuperDog.
        /// </summary>
        protected Dog LoginDefaultDemo()
        {
            DogFeature feature = DogFeature.Default;

            Dog dog = new Dog(feature);

            DogStatus status = dog.Login(VendorCode.Code, scope);

            // Please note that there is no need to call
            // a logout function explicitly - although it is
            // recommended. The garbage collector will perform
            // the logout when disposing the object.
            // If you need more control over the logout procedure
            // perform one of the more advanced tasks.
            return(dog.IsLoggedIn() ? dog : null);
        }
コード例 #11
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to perform a login and a logout
        /// using the default feature.
        /// </summary>
        protected void LoginLogoutDefaultDemo()
        {
            DogFeature feature = DogFeature.Default;
            Dog        dog     = new Dog(feature);
            DogStatus  status  = dog.Login(VendorCode.Code, scope);

            if (DogStatus.StatusOk == status)
            {
                status = dog.Logout();
            }

            // recommended, but not mandatory
            // this call ensures that all resources to SuperDog
            // are freed immediately.
            dog.Dispose();
        }
コード例 #12
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to login using a feature id.
        /// </summary>
        protected Dog LoginDemo(DogFeature feature)
        {
            Verbose("Login Demo with Feature: " +
                    feature.FeatureId.ToString());

            // create a dog object using a feature
            // and perform a login using the vendor code.
            Dog dog = new Dog(feature);

            DogStatus status = dog.Login(VendorCode.Code, scope);

            ReportStatus(status);

            Verbose("");

            return(dog.IsLoggedIn() ? dog : null);
        }
コード例 #13
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to perform a login using the default
        /// feature and how to perform an automatic logout
        /// using the SuperDog's Dispose method.
        /// </summary>
        protected void LoginDisposeDemo()
        {
            Verbose("Login/Dispose Demo with Default Feature (DogFeature.Default)");

            DogFeature feature = DogFeature.Default;

            Dog dog = new Dog(feature);

            DogStatus status = dog.Login(VendorCode.Code, scope);

            ReportStatus(status);

            Verbose("Disposing object - will perform an automatic logout");
            dog.Dispose();

            Verbose("");
        }
コード例 #14
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Demonstrates how to perform a login and an automatic
        /// logout using C#'s scope clause.
        /// </summary>
        protected void LoginDefaultAutoDemo()
        {
            Verbose("Login Demo with Default Feature (DogFeature.Default)");

            DogFeature feature = DogFeature.Default;

            // this will perform a logout and object disposal
            // when the using scope is left.
            using (Dog dog = new Dog(feature))
            {
                DogStatus status = dog.Login(VendorCode.Code, scope);
                ReportStatus(status);

                Verbose("Object going out of scope - System will call Dispose");
            }

            Verbose("");
        }
コード例 #15
0
ファイル: dogapidemo.cs プロジェクト: xrfmail/GitHub
        /// <summary>
        /// Runs the API demo.
        /// </summary>
        public void RunDemo(string scope)
        {
            try
            {
                this.scope = scope;

                // Demonstrate the different login methods
                LoginDefaultAutoDemo();
                LoginLogoutDefaultDemo();
                LoginDisposeDemo();

                // Demonstrates how to get a list of available features
                GetInfoDemo();

                // run the API demo using the default feature
                Dog dog = LoginDefaultDemo();
                SessionInfoDemo(dog);
                ReadWriteDemo(dog, FileId);
                ReadWritePosDemo(dog, FileId);
                EncryptDecryptDemo(dog);
                TestTimeDemo(dog);
                LogoutDemo(ref dog);

                // run the API demo using feature id 42
                dog = LoginDemo(new DogFeature(DogFeature.FromFeature(42).Feature));
                SessionInfoDemo(dog);
                ReadWriteDemo(dog, FileId);
                ReadWritePosDemo(dog, FileId);
                EncryptDecryptDemo(dog);
                TestTimeDemo(dog);
                LogoutDemo(ref dog);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #16
0
ファイル: sample.cs プロジェクト: miradel51/HownetServer
        public DogStatus CheckKey()
        {
            DogStatus status;
            int       i, j;

            i = j = 0;

            Dog curDog = new Dog(new DogFeature(DogFeature.FromFeature(EncryptionArray1.GenArrFeatureID).Feature));

            /************************************************************************
             * Login
             *   establishes a context for SuperDog
             */
            status = curDog.Login(VendorCode.Code, scope);
            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);
            }


            //Generate a random index number
            Random random = new Random();

            i = random.Next(EncryptionArray1.GenerateCount);

            byte[] queryData = new byte[EncryptionArray1.EncryptDataLen];
            for (j = 0; j < EncryptionArray1.EncryptDataLen; ++j)
            {
                queryData[j] = encryptArr1.encryptionArray[i, 0][j];
            }

            /**********************************************************************
             * dog_encrypt encrypts a block of data using SuperDog (minimum buffer
             * size is 16 bytes)
             */
            status = curDog.Encrypt(queryData);
            if (DogStatus.StatusOk != status)
            {
                Console.WriteLine("Dog encrypt failed with status: " + status);
                return(status);
            }

            for (j = 0; j < EncryptionArray1.EncryptDataLen; ++j)
            {
                if (0 != (queryData[j] ^ encryptArr1.encryptionArray[i, 1][j]))
                {
                    Console.WriteLine("Encrypted data is wrong.");
                    curDog.Logout();
                    return(DogStatus.InternalError);
                }
            }

            Console.WriteLine("Check Dog using encryption array success.");

            status = curDog.Logout();
            return(status);
        }
コード例 #17
0
ファイル: sample.cs プロジェクト: miradel51/HownetServer
        public DogStatus DecryptString()
        {
            DogStatus status;
            UInt32    i = 0;

            byte[] bufData;
            byte[] strTmp;
            string strContents;

            Dog curDog = new Dog(new DogFeature(DogFeature.FromFeature(EncryptedString1.EncryptBufFeatureID).Feature));

            /************************************************************************
             * Login
             *   establishes a context for SuperDog
             */
            status = curDog.Login(VendorCode.Code, scope);
            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);
            }

            bufData = new byte[encrString1.EncryptBufLen];
            for (i = 0; i < encrString1.EncryptBufLen; ++i)
            {
                bufData[i] = encrString1.encryptStrArr[i];
            }

            // decrypt the data.
            // on success we convert the data back into a
            // human readable string.
            status = curDog.Decrypt(bufData);
            if (DogStatus.StatusOk != status)
            {
                Console.WriteLine("Dog decrypt failed with status: " + status);
                curDog.Logout();
                return(status);
            }

            //If source string length is less than 16, we need cut the needless buffer
            if (encrString1.EncryptBufLen > encrString1.SourceBufLen)
            {
                strTmp = new byte[encrString1.SourceBufLen];
                for (i = 0; i < encrString1.SourceBufLen; ++i)
                {
                    strTmp[i] = bufData[i];
                }
                strContents = UTF8Encoding.UTF8.GetString(strTmp);
            }
            else
            {
                strContents = UTF8Encoding.UTF8.GetString(bufData);
            }

            //Use the decrypted string do some operation
            if (0 == encrString1.isString)
            {
                DumpBytes(bufData, encrString1.SourceBufLen);
            }
            else
            {
                Console.WriteLine("The decrypted string is: \"" + strContents + "\".");
            }

            status = curDog.Logout();
            return(status);
        }