

Var encryptedByteArray = rsa.The Rijndael (now referred to as Advanced Encryption Standard ) and Triple Data Encryption Standard (3DES) algorithms provide greater security than DES because they are more computationally intensive. Var dataToEncrypt = _encoder.GetBytes(data) Var rsa = new RSACryptoServiceProvider() Public static string Encrypt(string data) Return _encoder.GetString(decryptedByte) Var decryptedByte = rsa.Decrypt(dataByte, false) Var rsa = new RSACryptoServiceProvider(bitSizeInts) Ĭonsole.WriteLine($"the private key made is: ) īyte dataByte = new byte įor (int i = 0 i < dataArray.Length i++)ĭataByte = Convert.ToByte(dataArray) String bitSize = Console.ReadLine().ToString() StreamWriter textWriter = new StreamWriter(new FileStream(outputFileInfo, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) Ĭonsole.WriteLine($"Do you have keys in the file? Y / N") ĬonsoleKey response = Console.ReadKey().Key Ĭonsole.WriteLine("Your encrypted message has been made and exported to the file") Ĭonsole.WriteLine("Your decrypted message has been made and exported to the file") Ĭonsole.WriteLine("Didn't get an E or a D") Ĭonsole.WriteLine("Tell me how many bits you want to make the RSA keys in, 1024, 2048, etc, then press enter") StreamWriter keyWriter = new StreamWriter(new FileStream(outputKeyInfo, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) StreamReader keyReader = new StreamReader(new FileStream(sourceKeys, FileMode.Open, FileAccess.Read, FileShare.None)) String sourceFile = Environment.GetFolderPath() + sourceKeys = Environment.GetFolderPath() + outputKeyInfo = Environment.GetFolderPath() + outputFileInfo = Environment.GetFolderPath() + textreader = new StreamReader(new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.None)) txt files on your desktop: SourceFile.txt, and SourceKeys.txt") Private static UnicodeEncoding _encoder = new UnicodeEncoding() Ĭonsole.WriteLine("Hello World! Let's encrypt some messages! :D") Ĭonsole.WriteLine("Have these. You also don’t need the OutputKeys.txt file or the OutputFile.txt file since though are generated by the program upon completionĢ8 July 2021: FileMode parameters changed from Create to OpenOrCreate, so that if a file is not changed it is not cleared The program will make keys with headers labeling the public and private keys explicitly. Higher bit sized keys take longer to generate though can encode longer messages per line of text (while it can of course take many lines of individual text, and high bit sizes are also mathematically more secure and complex)Ģ7 July 2021: Edits done. There is a minimum of around 1024 bits and a maximum of 4096 bits. When you enter the keys in the SourceKeys.txt file, you do not need empty spaces as it will work without them, they are there for ease of useĮncryption key size will be asked of when you want to generate keys. If there is an overflow exception, it is most likely because you’re attempting to encrypt text that is already encrypted, or you’re trying to encrypt a line that is too large for the bit size you used (so make the key sizes bigger or the length of the sentences smaller), and so far this program does not handle double encryption yet. The OutputKeys.txt file gets cleared if you don’t make new keys, so be sure to save your keys every time immediately after you generate new ones. Will finesse the mechanics of the program sometime soon If you run this program with the SourceKeys.txt file only having the public key to encrypt something, it will run to completion, though decrypting messages does need the private key. The private key however is needed to decrypt a message that was encrypted with your public key. When generating keys with this program, the first half is the public key which you can give to anyone, even publicly for everyone to see. When encrypting something in RSA, only the public key in needed. You will need four text files on your desktop: SourceFile.txt, SourceKeys.txt, OutputKeys.txt, and OutputFile.txt

You can also make new keys to suit your purposes

This program allows you to encrypt and decrypt messages with RSA keys.
