Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This project will require you to create three C# projects using Visual Studio Code. When run, one will create a public / private key pair,

This project will require you to create three C# projects using Visual Studio Code. When run, one will create a public / private key pair, one will use the public key created to encrypt a message given as a string and one will use the private key created to decrypt the encrypted message.

You must name the folder of the C# project that encrypts a string message using the created public key p3_encryption_your-ulid. (This is the only one of the three that you will submit.) When all three of your projects are functioning correctly,

  1. Run the C# project that generates a public / private key pair.

  2. Project p3_encryption_your-ulid:

    1. (a) clean p3_encryption_your-ulid.

    2. (b) copy the public key file created in step #1 and paste it in the main folder of

      p3_encryption_your-ulid.

    3. (c) Zip p3_encryption_your-ulid and submit it on Moodle.

The TA will run your p3_encryption_your-ulid to generate an encrypted form of a secret message specifically for you, which he will then email to you as an attached file.

You will download the file attached to the email and use the public key you created earlier to decrypt the secret message in the file.

Finally, you will copy and paste the decrypted message to Moodle.

General Requirements

Use of Combine(CurrentDirectory, "file-name") to create file paths that end in the main folder /

directory of the project is required for all files.

using System;

using System.IO;

using static System.Environment;

using static System.IO.Path;

using System.Security.Cryptography;

using System.Text;

using System.Collections;

using System.Collections.Generic;

using System.Xml.Serialization;

using System.Xml;

namespace RSAEnc

{

public class RsaEnc

{

private static RSACryptoServiceProvider csp = new RSACryptoServiceProvider(2048);

private RSAParameters _privateKey;

private RSAParameters _publicKey;

public RsaEnc()

{

using (var rsa = new RSACryptoServiceProvider())

{

File.WriteAllText(Combine(CurrentDirectory,"PublicKeyOnly.xml"), rsa.ToXmlString (false));

File.WriteAllText(Combine(CurrentDirectory,"PublicPrivate.xml"), rsa.ToXmlString (true));

}

}

public string PublicKeyString()

{

var sw = new StringWriter();

var xs = XmlSerializer(typeof(RSAParameters));

xs.Serialize(sw, _publicKey);

return sw.ToString();

}

public string Encrpyt(string plainText)

{

byte[] datain = Encoding.UTF8.GetBytes (plainText);

string publicKeyOnly = File.ReadAllText(Combine(CurrentDirectory,"PublicKeyOnly.xml"));

byte[] encrypted;

using (var rsaPublicOnly = new RSACryptoServiceProvider()

{

rsaPublicOnly.FromXmlString (publicKeyOnly);

encrypted = rsaPublicOnly.Encrypt (datain, true);

}

File.WriteAllBytes(Combine(CurrentDirectory,"encryptedmessage"),encrypted);

}

public string Decrypt(string cypherText)

{

byte[] dataout = File.ReadAllBytes( Combine(CurrentDirectory,"encryptedmessage"));

string publicPrivate = File.ReadAllText( Combine(CurrentDirectory,"PublicPrivate.xml"));

string messageDecrypted;

byte[] decrypted;

using (var rsaPublicPrivate = new RSACryptoServiceProvider())

{

rsaPublicPrivate.FromXmlString (publicPrivate);

decrypted = rsaPublicPrivate.Decrypt(dataout,true);

messageDecrypted = Encoding.UTF8.GetString(decrypted);

}

Console.WriteLine("decrypted: " + messageDecrypted);

}

}

}

using System;

using System.IO;

using static System.Environment;

using static System.IO.Path;

using System.Security.Cryptography;

using System.Collections;

using System.Collections.Generic;

using System.Xml.Serialization;

using System.Xml;

using RSAEnc;

namespace p3_Encryption_C00289039

{

class Program

{

static void Main(string[] args)

{

RsaEnc rs = new RsaEnc();

string cypher = String.Empty;

Console.WriteLine($"PublicKey: {rs.PublicKeyString()} ");

Console.WriteLine("Enter your message that will be encrypted: ");

var text = Console.ReadLine();

if (text != String.Empty)

{

var cypher = rs.Encrypt(text);

Console.WriteLine($"Cypher Text: {cypher} ");

}

Console.WriteLine("Press enter to decypher your message: ");

Console.WriteLine();

var decryptedmessage = rs.Decrypt(cypher);

Console.WriteLine("Decrypted Text: ");

Console.WriteLine(decryptedmessage);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

LO4 List options for development needs analyses.

Answered: 1 week ago