using System.Collections.Generic; using System.IO; using System.Xml; using Packt.Shared; using static System.Console; using static System.IO.Path; using static System.Environment; namespace Exercise02 {   class Program   {     static void Main(string[] args)     {       WriteLine("You must enter a password to encrypt the sensitive data in the document.");       WriteLine("You must enter the same passord to decrypt the document later.");       Write("Password: ");       string password = ReadLine();       // define two example customers and       // note they have the same password       var customers = new List       {         new Customer         {           Name = "Bob Smith",           CreditCard = "1234-5678-9012-3456",           Password = "Pa$$w0rd",         },         new Customer         {           Name = "Leslie Knope",           CreditCard = "8002-5265-3400-2511",           Password = "Pa$$w0rd",         }       };       // define an XML file to write to       string xmlFile = Combine(CurrentDirectory,         "..", "protected-customers.xml");       var xmlWriter = XmlWriter.Create(xmlFile,         new XmlWriterSettings { Indent = true });       xmlWriter.WriteStartDocument();       xmlWriter.WriteStartElement("customers");       foreach (var customer in customers)       {         xmlWriter.WriteStartElement("customer");         xmlWriter.WriteElementString("name", customer.Name);         // to protect the credit card number we must encrypt it         xmlWriter.WriteElementString("creditcard",           Protector.Encrypt(customer.CreditCard, password));                  // to protect the password we must salt and hash it         // and we must store the random salt used         var user = Protector.Register(customer.Name, customer.Password);         xmlWriter.WriteElementString("password", user.SaltedHashedPassword);         xmlWriter.WriteElementString("salt", user.Salt);         xmlWriter.WriteEndElement();       }       xmlWriter.WriteEndElement();       xmlWriter.WriteEndDocument();       xmlWriter.Close();       WriteLine();       WriteLine("Contents of the protected file:");       WriteLine();       WriteLine(File.ReadAllText(xmlFile));     }   } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

using System.Collections.Generic;

using System.IO;

using System.Xml;

using Packt.Shared;

using static System.Console;

using static System.IO.Path;

using static System.Environment;

namespace Exercise02

{

  class Program

  {

    static void Main(string[] args)

    {

      WriteLine("You must enter a password to encrypt the sensitive data in the document.");

      WriteLine("You must enter the same passord to decrypt the document later.");

      Write("Password: ");

      string password = ReadLine();

      // define two example customers and

      // note they have the same password

      var customers = new List<Customer>

      {

        new Customer

        {

          Name = "Bob Smith",

          CreditCard = "1234-5678-9012-3456",

          Password = "Pa$$w0rd",

        },

        new Customer

        {

          Name = "Leslie Knope",

          CreditCard = "8002-5265-3400-2511",

          Password = "Pa$$w0rd",

        }

      };

      // define an XML file to write to

      string xmlFile = Combine(CurrentDirectory,

        "..", "protected-customers.xml");

      var xmlWriter = XmlWriter.Create(xmlFile,

        new XmlWriterSettings { Indent = true });

      xmlWriter.WriteStartDocument();

      xmlWriter.WriteStartElement("customers");

      foreach (var customer in customers)

      {

        xmlWriter.WriteStartElement("customer");

        xmlWriter.WriteElementString("name", customer.Name);

        // to protect the credit card number we must encrypt it

        xmlWriter.WriteElementString("creditcard",

          Protector.Encrypt(customer.CreditCard, password));

        

        // to protect the password we must salt and hash it

        // and we must store the random salt used

        var user = Protector.Register(customer.Name, customer.Password);

        xmlWriter.WriteElementString("password", user.SaltedHashedPassword);

        xmlWriter.WriteElementString("salt", user.Salt);

        xmlWriter.WriteEndElement();

      }

      xmlWriter.WriteEndElement();

      xmlWriter.WriteEndDocument();

      xmlWriter.Close();

      WriteLine();

      WriteLine("Contents of the protected file:");

      WriteLine();

      WriteLine(File.ReadAllText(xmlFile));

    }

  }

}

2. Update code for Exercise 2 from the textbook:
a) Open the Source code for Exercise02 from our textbook Chapter 10
v Chapter10
> CryptographyLib
> EncryptionApp
v Exercise02
C Customer.cs
Exercise02.csproj
Program.cs
Add one more customer with your name and fake password and credit card information.
Run the program. Save or memorize the password you provided.
Observe the XML file created in the same folder, take a screenshot.
b) Observe in the .csproj file the library this App refers to.
Update that library to 100000 iterations, update the salt to any word of your choice of about the
same size as current salt.
Change your Exercise02 code to store result into protected-customers2.xml.
Run the code using the same password.
Compare created XMLS. Write a short summary of this comparison.
Provide screenshot of XML files
Transcribed Image Text:2. Update code for Exercise 2 from the textbook: a) Open the Source code for Exercise02 from our textbook Chapter 10 v Chapter10 > CryptographyLib > EncryptionApp v Exercise02 C Customer.cs Exercise02.csproj Program.cs Add one more customer with your name and fake password and credit card information. Run the program. Save or memorize the password you provided. Observe the XML file created in the same folder, take a screenshot. b) Observe in the .csproj file the library this App refers to. Update that library to 100000 iterations, update the salt to any word of your choice of about the same size as current salt. Change your Exercise02 code to store result into protected-customers2.xml. Run the code using the same password. Compare created XMLS. Write a short summary of this comparison. Provide screenshot of XML files
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education