Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <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);
                }
            }
        }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }