Esempio n. 1
0
        public void Test_PEK_Encryption()
        {
            byte[] encryptedBytes     = DUKPT.Encrypt(_bdk, _ksn, Encoding.UTF8.GetBytes(_clearData), DUKPTVariant.PIN);
            string encryptedHexResult = BitConverter.ToString(encryptedBytes).Replace("-", "");

            Assert.AreEqual(encryptedHexResult, _expectedEncryptedHexPEK);
        }
Esempio n. 2
0
        public void Test_PEK_Decryption()
        {
            byte[] decryptedBytes = DUKPT.Decrypt(_bdk, _ksn, _expectedEncryptedHexPEK.HexStringToByteArray(), DUKPTVariant.PIN);
            string decryptedData  = Encoding.UTF8.GetString(decryptedBytes);

            Assert.AreEqual(decryptedData, _clearData);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string bdk = "0123456789ABCDEFFEDCBA9876543210";
            string ksn = "629949012C0000000003";

            byte[] superSecretMessage = Encoding.UTF8.GetBytes("1234");
            byte[] encryptedData      = DUKPT.Encrypt(bdk, ksn, superSecretMessage, DUKPTVariant.PIN);
            String hexres             = BitConverter.ToString(encryptedData);

            hexres = hexres.Replace("-", "");
            Console.WriteLine("Encrypted Data: " + hexres);

            byte[] decryptedData       = DUKPT.Decrypt(bdk, ksn, encryptedData, DUKPTVariant.PIN);
            string superSecretMessage1 = Encoding.UTF8.GetString(decryptedData);

            Console.WriteLine("Decrypted Data: " + superSecretMessage1);
        }
Esempio n. 4
0
 public void Test_PEK_Encryption_Empty_KSN()
 {
     byte[] decryptedBytes = DUKPT.Encrypt(_bdk, string.Empty, Encoding.UTF8.GetBytes(_clearData), DUKPTVariant.PIN);
 }
Esempio n. 5
0
 public void Test_PEK_Encryption_Null_BDK()
 {
     byte[] decryptedBytes = DUKPT.Encrypt(null, _ksn, Encoding.UTF8.GetBytes(_clearData), DUKPTVariant.PIN);
 }
Esempio n. 6
0
 public void Test_PEK_Encryption_Null_Data()
 {
     byte[] decryptedBytes = DUKPT.Encrypt(_bdk, _ksn, null, DUKPTVariant.PIN);
 }
Esempio n. 7
0
 public void Test_PEK_Encryption_Invalid_Length_KSN()
 {
     byte[] encryptedBytes = DUKPT.Encrypt(_bdk, _ksn.Substring(0, 2), Encoding.UTF8.GetBytes(_clearData), DUKPTVariant.PIN);
 }
Esempio n. 8
0
 public void Test_DEK_Decryption_Empty_KSN()
 {
     byte[] decryptedBytes = DUKPT.Decrypt(_bdk, string.Empty, _expectedEncryptedHexDEK.HexStringToByteArray(), DUKPTVariant.Data);
 }
Esempio n. 9
0
 public void Test_DEK_Decryption_Null_BDK()
 {
     byte[] decryptedBytes = DUKPT.Decrypt(null, _ksn, _expectedEncryptedHexDEK.HexStringToByteArray(), DUKPTVariant.Data);
 }
Esempio n. 10
0
 public void Test_DEK_Decryption_Invalid_Length_BDK()
 {
     byte[] encryptedBytes = DUKPT.Decrypt(_bdk.Substring(0, _bdk.Length / 2), _ksn, _expectedEncryptedHexDEK.HexStringToByteArray(), DUKPTVariant.Data);
 }
Esempio n. 11
0
 public void Test_DEK_Encryption_Empty_BDK()
 {
     byte[] decryptedBytes = DUKPT.Encrypt(string.Empty, _ksn, Encoding.UTF8.GetBytes(_clearData), DUKPTVariant.Data);
 }
Esempio n. 12
0
 public void Test_DEK_Encryption_Null_KSN()
 {
     byte[] decryptedBytes = DUKPT.Encrypt(_bdk, null, Encoding.UTF8.GetBytes(_clearData), DUKPTVariant.Data);
 }
Esempio n. 13
0
 public void Test_DEK_Encryption_Invalid_Length_BDK()
 {
     byte[] encryptedBytes = DUKPT.Encrypt(_bdk.Substring(0, _bdk.Length / 2), _ksn, Encoding.UTF8.GetBytes(_clearData), DUKPTVariant.Data);
 }
Esempio n. 14
0
 public void Test_PEK_Decryption_Empty_BDK()
 {
     byte[] decryptedBytes = DUKPT.Decrypt(string.Empty, _ksn, _expectedEncryptedHexDEK.HexStringToByteArray(), DUKPTVariant.PIN);
 }
Esempio n. 15
0
 public void Test_PEK_Decryption_Null_KSN()
 {
     byte[] decryptedBytes = DUKPT.Decrypt(_bdk, null, _expectedEncryptedHexDEK.HexStringToByteArray(), DUKPTVariant.PIN);
 }
Esempio n. 16
0
 public void Test_DEK_Decryption_Null_Data()
 {
     byte[] decryptedBytes = DUKPT.Decrypt(_bdk, _ksn, null, DUKPTVariant.Data);
 }
Esempio n. 17
0
 public void Test_PEK_Decryption_Invalid_Length_KSN()
 {
     byte[] encryptedBytes = DUKPT.Decrypt(_bdk, _ksn.Substring(0, 2), _expectedEncryptedHexPEK.HexStringToByteArray(), DUKPTVariant.PIN);
 }
Esempio n. 18
0
        public static void WorkThreadFunction()
        {
            string             bdk            = "0123456789ABCDEFFEDCBA9876543210";
            ProcessTransResult transResult    = poslink.ProcessTrans();
            ManageResponse     manageResponse = poslink.ManageResponse;

            Console.WriteLine("BDK: " + bdk);
            sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "BDK: " + bdk);
            sb.AppendLine();

            if (transResult.Code.Equals(ProcessTransResultCode.OK))
            {
                Console.WriteLine("From POSLink Encryption: ");
                sb.Append("From POSLink Encryption: ");
                sb.AppendLine();
                Console.WriteLine(manageResponse.ResultCode);
                sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "ProcessTransResult code: " + manageResponse.ResultCode);
                sb.AppendLine();
                Console.WriteLine(manageResponse.ResultTxt);
                sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "ProcessTransResult msg: " + manageResponse.ResultTxt);
                sb.AppendLine();
                Console.WriteLine("KSN: " + manageResponse.KSN);
                sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "KSN: " + manageResponse.KSN);
                sb.AppendLine();
                Console.WriteLine("PAN: " + manageResponse.PAN);
                sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "PAN: " + manageResponse.PAN);
                sb.AppendLine();
                Console.WriteLine("Masked PAN: " + manageResponse.MaskedPAN);
                sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "Masked PAN: " + manageResponse.MaskedPAN);
                sb.AppendLine();
                Console.WriteLine("From third party Decryption: ");
                sb.Append("From third party Decryption: ");
                sb.AppendLine();

                /*
                 * byte[] superSecretMessage = Encoding.UTF8.GetBytes("5147501000000018"); //hard coded test card PAN
                 * byte[] encryptedData = DUKPT.Encrypt(bdk, ksn, superSecretMessage, DUKPTVariant.Data);
                 * //Console.WriteLine(String.Join("",encryptedData));
                 * String hexres = BitConverter.ToString(encryptedData);
                 * hexres = hexres.Replace("-", "");
                 * Console.WriteLine("Encrypted Data: " + hexres);
                 */

                string ksn = manageResponse.KSN;
                byte[] num = StringToByteArray(manageResponse.PAN);
                try {
                    byte[] decryptedData = DUKPT.Decrypt(bdk, ksn, num, DUKPTVariant.Data);
                    string res           = Encoding.UTF8.GetString(decryptedData);
                    Console.WriteLine("Decrypted Data: " + res + "\n");
                    sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "Decrypted Data: " + res + "\n");
                    sb.AppendLine();
                }
                catch (Exception e)
                {
                    sb.Append(e);
                    sb.AppendLine();
                    sb.AppendLine();
                }
            }
            else
            {
                sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "ProcessTransResult code: " + manageResponse.ResultCode);
                sb.AppendLine();
                sb.Append("[" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "]" + "ProcessTransResult msg: " + manageResponse.ResultTxt);
                sb.AppendLine();
            }
        }