static void InternalTesting() { try { foreach (var item in trackPayload) { MSRTrackDataDecryptor decryptor = new MSRTrackDataDecryptor(); // decryptor in action byte[] trackInformation = decryptor.DecryptData(item.KSN, item.EncryptedData); string decryptedTrack = ConversionHelper.ByteArrayToHexString(trackInformation); //1234567890|1234567890|12345 Debug.WriteLine($"OUTPUT ____: {decryptedTrack}"); Console.WriteLine($"OUTPUT : [{decryptedTrack}]"); byte[] expectedValue = ConversionHelper.HexToByteArray(item.DecryptedData); bool result = StructuralComparisons.StructuralEqualityComparer.Equals(expectedValue, trackInformation); Console.WriteLine($"EQUAL : [{result}]"); MSRTrackData trackData = decryptor.RetrieveTrackData(trackInformation); Console.WriteLine($"CHOLDER: [{trackData.Name}]"); } } catch (Exception e) { Console.WriteLine($"EXCEPTION: {e.Message}"); } }
public void DecryptData_ShouldDecryptTrackData_WhenCalled(string ksn, string encryptedTrack, string decryptedTrack) { byte[] expectedValue = ConversionHelper.HexToByteArray(decryptedTrack); byte[] actualValue = subject.DecryptData(ksn, encryptedTrack); Assert.Equal(expectedValue, actualValue); }
static void MsrTrackDecryption(IConfiguration configuration, int index) { var trackData = configuration.GetSection("MSRTrackDataGroup:MSRTrackData") .GetChildren() .ToList() .Select(x => new { msrTrackKsn = x.GetValue <string>("KSN"), msrTrackIV = x.GetValue <string>("IV"), msrEncryptedTrackData = x.GetValue <string>("EncryptedTrackData"), msrDecryptedTrackData = x.GetValue <string>("DecryptedTrackData") }); // Is there a matching item? if (trackData.Count() > index) { string msrTrackKsn = trackData.ElementAt(index).msrTrackKsn; string msrTrackIV = trackData.ElementAt(index).msrTrackIV; string msrEncryptedTrackData = trackData.ElementAt(index).msrEncryptedTrackData; string msrDecryptedTrackData = trackData.ElementAt(index).msrDecryptedTrackData; try { //1234567890|1234567890|12345 Console.WriteLine($"\r\n==== [ MSR TRACK DECRYPTION ] ===="); MSRTrackDataDecryptor decryptor = new MSRTrackDataDecryptor(); Debug.WriteLine($"KSN _______: {msrTrackKsn}"); Console.WriteLine($"KSN : {msrTrackKsn}"); //Console.WriteLine($"DATA : {msrEncryptedTrackData}"); // decryptor in action byte[] trackInformation = decryptor.DecryptData(msrTrackKsn, msrEncryptedTrackData); string decryptedTrack = ConversionHelper.ByteArrayToHexString(trackInformation); //1234567890|1234567890|12345 //Console.WriteLine($"OUTPUT : {decryptedTrack}"); Debug.WriteLine($"OUTPUT ____: {decryptedTrack}"); //MSRTrackData trackInfo = decryptor.RetrieveAdditionalData(trackInformation); MSRTrackData trackInfo = decryptor.RetrieveTrackData(trackInformation); string expirationDate = ""; if (trackInfo.ExpirationDate.Length >= 4) { expirationDate = trackInfo.ExpirationDate.Substring(0, 2) + "/" + trackInfo.ExpirationDate.Substring(2, 2); } //1234567890|1234567890|12345 Debug.WriteLine($"PAN DATA : {trackInfo.PANData}"); Debug.WriteLine($"EXPIR (YY/MM): {expirationDate}"); Debug.WriteLine($"SERVICE CODE : {trackInfo.ServiceCode}"); Debug.WriteLine($"DISCRETIONARY: {trackInfo.DiscretionaryData}"); Console.WriteLine($"EXPIRATE : {trackInfo.ExpirationDate}"); Console.WriteLine($"SERV CODE: {trackInfo.ServiceCode}"); byte[] expectedValue = ConversionHelper.HexToByteArray(msrDecryptedTrackData); bool result = StructuralComparisons.StructuralEqualityComparer.Equals(expectedValue, trackInformation); Console.WriteLine($"EQUAL : [{result}]"); //MSRTrackData trackData = decryptor.RetrieveTrackData(trackInformation); //Console.WriteLine($"CHOLDER: [{trackData.Name}]"); } catch (Exception e) { Console.WriteLine($"EXCEPTION: {e.Message}"); } } }