Exemple #1
0
        //#############################
        //#Writing and Reading methods#
        //#############################

        /// <summary>
        /// First encrypts, and then saves the login credentials to a file
        /// </summary>
        /// <param name="FromAddress">The FromAddress to be encrypted</param>
        /// <param name="FromPass">The FromPass to be encrypted</param>
        /// <param name="Path">The path of the file</param>
        /// <param name="EncryptionPassword">The password used for the encryption</param>
        public static void WriteCredentialsToFile(string FromAddress, string FromPass, string Path, string EncryptionPassword)
        {
            // Declare variables
            string EncryptedFromAddress, EncryptedFromPass;

            // Create a new instance of the FileStream class
            FileStream fileStream = File.OpenWrite(Path);

            // Create a new instance of he BinaryWriter class
            BinaryWriter writer = new BinaryWriter(fileStream);

            // Encrypt the FromAddress and Frompass
            EncryptedFromAddress = EncryptionClass.Encrypt(FromAddress, EncryptionPassword);
            EncryptedFromPass    = EncryptionClass.Encrypt(FromPass, EncryptionPassword);

            // Write the credentials to the file
            writer.Write(EncryptedFromAddress);
            writer.Write(EncryptedFromPass);

            // Close the BinaryWriter
            writer.Close();
        }
Exemple #2
0
        /// <summary>
        /// Reads and decrypts the FromAddress and Frompass from the file where they're saved
        /// </summary>
        /// <param name="Path"></param>
        /// <param name="EncryptionPassword">The password used for the encryption</param>
        public static void ReadCredentialsFromFile(string Path, string EncryptionPassword)
        {
            // Create a new instance of the FileStream class
            FileStream fileStream = File.OpenRead(Path);

            // Create a new instance of the BinaryReader class
            BinaryReader reader = new BinaryReader(fileStream);

            // Read the file
            string EncryptedFromAddress = reader.ReadString();
            string EncryptedFromPass    = reader.ReadString();

            // Create an array to store the decrypted data in
            string[] DecryptedData = new string[2];

            // Decrypt the FromAddress and FromPass
            DecryptedData[0] = EncryptionClass.Decrypt(EncryptedFromAddress, EncryptionPassword);
            DecryptedData[1] = EncryptionClass.Decrypt(EncryptedFromPass, EncryptionPassword);

            // Assign the variables
            FromAddress = DecryptedData[0];
            FromPass    = DecryptedData[1];
        }