// The general function to encrypt a mail, depending on settings // Uses asymmetric.cs and symmetric.cs functions public static email encryptMail(email mail, bool useSymmetric, string symmetricKey, bool useAsymmetric, MerMail.Asymmetric.Key public_key) { // We are maybe going to modify contents in the mail, so we store it email rtn = mail; // We are maybe going to encrypt the symmetric key, so we store it too string symKey = symmetricKey; // We'll make it easy for the user to know, if the symmetric key // is encrypted or not string symKeyName = "symmetric_raw.txt"; string diagTitle = "Save symmetric key to file"; // We symmetricly encrypt the message body (if chosen) if (useSymmetric) { // We'll encrypt the message, while we still know the symmetric key rtn.body = MerMail.Symmetric.EncryptString(symKey, rtn.body); // We asymmetricly encrypt the symmetric key (if chosen) if (useAsymmetric) { symKey = MerMail.Asymmetric.EncryptString(symmetricKey, public_key); // Now, we know that the symmetric key is encrypted, so we're // going to tell the user that we encrypted it symKeyName = "symmetric_encrypted.txt"; diagTitle = "Save encrypted symmetric key to file"; } } // Can be saved to any filetype (but we like .txt) MerMail.Program.saveFile(symKeyName, diagTitle, "Any (*.*)", "*.*", symKey); return rtn; }
// The general function to decrypt a mail, depending on settings // Uses asymmetric.cs and symmetric.cs functions public static email decryptMail(email mail, bool useSymmetric, string symmetricKey, bool useAsymmetric, MerMail.Asymmetric.Key privatekey) { // We are maybe going to modify contents in the mail, so we store it email rtn = mail; // We are maybe going to decrypt the symmetric key, so we store it too string symKey = symmetricKey; // We symmetricly decrypt the message body (if chosen) if (useSymmetric) { // we asymmetricly decrypt the symmetric key (if chosen) if (useAsymmetric) { symKey = MerMail.Asymmetric.DecryptString(symmetricKey, privatekey); } rtn.body = MerMail.Symmetric.DecryptString(symKey, rtn.body); } return rtn; }
public DecryptedMail(MerMail.Program.email mail) { currentMail = mail; InitializeComponent(); }