Example #1
0
        /// <summary>
        /// Encrypt file contents into multiple lines
        /// </summary>
        /// <param name="fileContents">Original file contents</param>
        /// <param name="encryptionPassword">Encryption password</param>
        /// <param name="salt">Cryptographically genereated salt key</param>
        /// <returns></returns>
        public static string[] EncryptFile(string[] fileContents, string encryptionPassword, string salt)
        {
            string fullString = "";

            foreach (string s in fileContents)
            {
                fullString += s + "@NL#";  //Characters denotes new line
            }
            string toEncrypt = fullString.Substring(0, fullString.Length - 4);

            string encrpytedData = salt + "|SSPP|" + AESTwoWayEncryption.Encrypt <TripleDESCryptoServiceProvider>(toEncrypt, encryptionPassword, salt); //Salt string partion point seperates data and salt

            return(SplitStringEveryN(encrpytedData, 20));
        }
Example #2
0
        /// <summary>
        /// Encrypt data to be put into the database (Two way encrpytion) || Not to be used for passwords
        /// </summary>
        /// <param name="data">Data to be encrypted</param>
        /// <param name="encryptionPass">Encrpytion password</param>
        /// <param name="isSearchTerm">Is this a database search term?</param>
        /// <returns></returns>
        public static string EncryptData(string data, string encryptionPass, bool isSearchTerm = false)
        {
            string salt = GenerateNewSALT(8);

            if (isSearchTerm)
            {
                salt = defaultSALT;
            }

            string encryptedString = AESTwoWayEncryption.Encrypt <TripleDESCryptoServiceProvider>(data, encryptionPass, salt);

            if (isSearchTerm)
            {
                return(encryptedString);
            }
            return(salt + encryptedString);
        }