예제 #1
0
        public void ChecksumSurvivesRoundtrip()
        {
            // Arrange
            byte[] derivedKey = new byte[16] {
                15, 200, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 104, 15, 16
            };
            byte[] initialCounter = new byte[] { 0xf0, 0xf1, 0xfb, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xf3, 0xff };

            SettingsAES_CTR settingsAES_CTR = new SettingsAES_CTR(initialCounter);

            SymmetricKeyAlgorithm skaAES_CTR = new SymmetricKeyAlgorithm(SymmetricEncryptionAlgorithm.AES_CTR, 128, settingsAES_CTR);

            PaymentCard paymentCard = new PaymentCard("Bank of  Dragon", "Cool Dragon", "Debit", "0000000000001234", "111", "11/20", "05/33", "Super cool card I have here");

            PaymentCardSecret paymentCardSecret = new PaymentCardSecret(paymentCard, "does not matter", skaAES_CTR, derivedKey);

            // Act
            string checksum1 = paymentCardSecret.GetChecksumAsHex();

            string json = JsonConvert.SerializeObject(paymentCardSecret, Formatting.Indented);

            PaymentCardSecret paymentCardSecret2 = JsonConvert.DeserializeObject <PaymentCardSecret>(json);

            // Assert
            Assert.AreEqual(64, checksum1.Length);
            Assert.AreEqual(checksum1, paymentCardSecret2.GetChecksumAsHex());
        }