Exemplo n.º 1
0
        /****************************************************************************/
        /// <summary>
        /// Decrypt a string that was previously encrypted using the above method
        /// </summary>
        /// <param name="data">Data to decrypt</param>
        /// <returns>The original unencrypted string</returns>
        public static async Task <string> Decrypt(this IEncryptor encryptor, string encrypted)
        {
            if (string.IsNullOrEmpty(encrypted))
            {
                return("");
            }

            try
            {
                var decrypted = await encryptor.DecryptChars(encrypted);

                char[] chDecrypted = decrypted.Item1;
                string sDecrypted  = new String(chDecrypted, 0, decrypted.Item2);

                chDecrypted.Clear();

                return(sDecrypted.Replace(((char)6).ToString(), "")); // Was getting weird char problems
            }
            catch (Exception ex)
            {
                _ = ex;

                return(encrypted);
            }
        }
Exemplo n.º 2
0
        /****************************************************************************/
        public static SecureString DecryptToSecure(this IEncryptor encryptor, string strEncrypted)
        {
            if (strEncrypted.Normalized() == "")
            {
                return(null);
            }

            int iLength = 0;

            char[] chDecrypted = encryptor.DecryptChars(strEncrypted, out iLength);

            try
            {
                return(ToSecureString(chDecrypted, iLength));
            }
            finally
            {
                chDecrypted.Clear();
            }
        }
Exemplo n.º 3
0
        /****************************************************************************/
        public static string Decrypt(this IEncryptor encryptor, string strEncrypted)
        {
            if (strEncrypted.Normalized() == "")
            {
                return("");
            }

            try
            {
                int    iLength      = 0;
                char[] chDecrypted  = encryptor.DecryptChars(strEncrypted, out iLength);
                string strDecrypted = new String(chDecrypted, 0, iLength);

                chDecrypted.Clear();

                return(strDecrypted.Replace(((char)6).ToString(), "")); // Was getting weird char problems
            }
            catch (Exception ex)
            {
                return(strEncrypted);
            }
        }