예제 #1
0
        /// <summary>
        /// Decrpyt data from the database (Two way encryption)
        /// </summary>
        /// <param name="encrpytedData">Data to be decrypted</param>
        /// <param name="encryptionPass">Encrpyption password</param>
        /// <param name="isSearchTerm">Is this a database search term?</param>
        /// <returns></returns>
        public static string DecrpytData(string encrpytedData, string encryptionPass, bool isSearchTerm = false)
        {
            if (isSearchTerm)
            {
                return(AESTwoWayEncryption.Decrypt <TripleDESCryptoServiceProvider>(encrpytedData, encryptionPass, defaultSALT));
            }

            string salt      = encrpytedData.Substring(0, 8);
            string toDecrypt = encrpytedData.Substring(8, encrpytedData.Count() - 8);

            return(AESTwoWayEncryption.Decrypt <TripleDESCryptoServiceProvider>(toDecrypt, encryptionPass, salt));
        }
예제 #2
0
        /// <summary>
        /// Decrypt file into original file contents
        /// </summary>
        /// <param name="fileContents">Original file contents</param>
        /// <param name="encryptionPassword">Encryption password</param>
        public static string[] DecryptFile(string[] encryptedContents, string encrpytionPassword)
        {
            string encryptionString = CombineStringArray(encryptedContents);

            string[] parts = encryptionString.Split(new string[] { "|SSPP|" }, StringSplitOptions.None); //Split encrypted data to get string and main contents
            string   salt  = parts[0];

            string decrpytedData = AESTwoWayEncryption.Decrypt <TripleDESCryptoServiceProvider>(parts[1], encrpytionPassword, salt);

            string[] seperatedString = decrpytedData.Split(new string[] { "@NL#" }, StringSplitOptions.None); //Split string back up into original lines
            return(seperatedString);
        }
예제 #3
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));
        }
예제 #4
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);
        }