public static void Execute(string choice) { var digest = new HmacDigest(); byte[] inputBuffer = new byte[1024]; Stream inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); Console.SetBufferSize(128, 1024); if (choice == "1") { Console.WriteLine("Please enter text for Encrypt:"); string inputText = Console.ReadLine(); Console.WriteLine("\nEncryptKey:"); CryptoAlgorithm settingsDecryptor = new CryptoAlgorithm("ENCRYPT", "FSCS", new AesManaged()); var value = settingsDecryptor.Encrypt(inputText); Console.WriteLine(value); } else if (choice == "2") { Console.WriteLine("Public App Key: " + digest.PublicKey.ToString()); Console.WriteLine("\nDigest: " + digest.HashedStringBase64); Console.WriteLine("\nEpoch Time: " + digest.EpochTime.ToString()); } else if (choice == "3") { Console.WriteLine("Hit Enter to exit, Cya!!!"); Console.ReadLine(); } else { Console.WriteLine("Invalid Choice, Hit Enter to exit"); } }
public void With_EncryptDecrypt() { CryptoAlgorithm algorithm = context.Build(); functionToInvoke = (data) => { var encrypted = algorithm.Encrypt(data); return(algorithm.Decrypt(encrypted)); }; }
private void EncryptButton_Click(object sender, RoutedEventArgs e) { byte[] textToEncodeBytes; if (filePath == string.Empty) { textToEncodeBytes = Encoding.ASCII.GetBytes(TextToEncryptTextBox.Text); } else { textToEncodeBytes = File.ReadAllBytes(filePath); } if (EncryptionKeyTextBox.Text.Length != 8) { MessageBox.Show("Key must be an 8byte string", "Error!"); return; } BitArray encryptionKey = new BitArray(Encoding.ASCII.GetBytes(EncryptionKeyTextBox.Text)); if (textToEncodeBytes.Length == 0) { MessageBox.Show("There is nothing to encode", "Error!"); } BitArray bitArrayToEncode = new BitArray(textToEncodeBytes).RevertEveryByte(); bool[] bitsToEncode = new bool[bitArrayToEncode.Count]; bitArrayToEncode.CopyTo(bitsToEncode, 0); DESBuilder builder = new DESBuilder(); builder.AddWholeDES(encryptionKey); CryptoAlgorithm des = builder.Build(); bool[] encrypted = des.Encrypt(bitsToEncode); encryptedBytes = encrypted.ToByteArray(); EncryptedTextBox.Text = Encoding.ASCII.GetString(encryptedBytes); filePath = string.Empty; //DecryptedTextBox.Text = Encoding.ASCII.GetString(des.Decrypt(encrypted).ToByteArray()); //byte[] returnMessage = messageWithoutPadding.ToByteArray(); //File.WriteAllBytes(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "decrypted.bmp"), returnMessage }