Пример #1
0
        private string calcPVV()
        {
            String PVV = String.Empty;
            //Step-1
            String TSP = getTSP();

            /*
             * //Step-2
             * String Step2Result = Util.DES(Util.Cryption.Encrypt, TSP, KeyA);
             *
             * //Step-3
             * String Step3Result = Util.DES(Util.Cryption.Decrypt, Step2Result, KeyB);
             *
             * //Step-4
             * String Step4Result = Util.DES(Util.Cryption.Encrypt, Step3Result, KeyA);
             */

            String Step4Result = String.Empty;

            try
            {
                HSMClient HSM = new HSMClient(new TcpClient(IP, Port));
                //HSMClient HSM = new HSMClient(new TcpClient("192.168.30.168", 1500));
                HSM.initOps();
                Step4Result = HSM.DES_Encrypt(DesMode.ECB, KeyLength.Double, 1, KeyPair.KP14, KeyA + KeyB, TSP);
                HSM.TermClient();
                HSM = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }


            //Step-5
            String Step5Result = String.Empty;
            String ExtractHex  = String.Empty;

            for (int i = 0; i < Step4Result.Length; i++)
            {
                if (Char.IsDigit(Step4Result, i))
                {
                    Step5Result += Step4Result.Substring(i, 1);
                }
                else
                {
                    ExtractHex += Step4Result.Substring(i, 1);
                }
            }

            //Step-6
            String Step6Result = String.Empty;

            for (int i = 0; i < ExtractHex.Length; i++)
            {
                Step6Result += (Convert.ToChar(ExtractHex.Substring(i, 1)) - 'A').ToString();
            }

            //Step-7
            String Concatenate = Step5Result + Step6Result;

            return(Concatenate.Substring(0, 4));
        }
Пример #2
0
        private String calcCVV(String pan, String expirationDate, String serviceCode)
        {
            String CVV = String.Empty;
            //Step-1
            String extractData = String.Empty, block1 = String.Empty, block2 = String.Empty;

            //Step-2
            extractData = (pan + expirationDate + serviceCode).PadRight(32, '0');

            //Step-3
            block1 = extractData.Substring(0, 16);
            block2 = extractData.Substring(16, 16);

            /*
             * //Step-4
             * String Step4Result = Util.DES(Util.Cryption.Encrypt, block1, KeyA);
             * throw new Exception(Step4Result);
             *
             * //Step-5
             * String XorResult = Util.xorBytes(Step4Result, block2);
             * String Step5Result = Util.DES(Util.Cryption.Encrypt, XorResult, KeyA);
             *
             * //Step-6
             * String Step6Result = Util.DES(Util.Cryption.Decrypt, Step5Result, KeyB);
             *
             * //Step-7
             * String Step7Result = Util.DES(Util.Cryption.Encrypt, Step6Result, KeyA);
             */

            ///*
            String Step4Result = String.Empty;
            String XorResult   = String.Empty;
            String Step7Result = String.Empty;

            try
            {
                HSMClient HSM = new HSMClient(new TcpClient(IP, Port));
                //HSMClient HSM = new HSMClient(new TcpClient("192.168.30.168", 1500));
                HSM.initOps();
                Step4Result = HSM.DES_Encrypt(DesMode.ECB, KeyLength.Single, 1, KeyPair.KP14, KeyA, block1);
                XorResult   = Util.xorBytes(Step4Result, block2);
                Step7Result = HSM.DES_Encrypt(DesMode.ECB, KeyLength.Double, 1, KeyPair.KP14, KeyA + KeyB, XorResult);
                HSM.TermClient();
                HSM = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //*/

            //Step-8
            String Step8Result = String.Empty;
            String ExtractHex  = String.Empty;

            for (int i = 0; i < Step7Result.Length; i++)
            {
                if (Char.IsDigit(Step7Result, i))
                {
                    Step8Result += Step7Result.Substring(i, 1);
                }
                else
                {
                    ExtractHex += Step7Result.Substring(i, 1);
                }
            }

            //Step-9
            String Step9Result = String.Empty;

            for (int i = 0; i < ExtractHex.Length; i++)
            {
                Step9Result += (Convert.ToChar(ExtractHex.Substring(i, 1)) - 'A').ToString();
            }

            //Step-10
            String Concatenate = Step8Result + Step9Result;

            return(Concatenate.Substring(0, 3));
        }