GetDataEncryptionKey() private static method

Gets the data encryption key.
private static GetDataEncryptionKey ( ) : string
return string
Beispiel #1
0
        /// <summary>
        /// Tries to encrypt the string. Use this in situations where you might just want to skip encryption if it doesn't work.
        /// You should use EncryptString in most cases.
        /// </summary>
        /// <param name="plainText">The plain text.</param>
        /// <param name="cypherText">The cypher text.</param>
        /// <returns></returns>
        public static bool TryEncryptString(string plainText, out string cypherText)
        {
            cypherText = null;

            string encryptionKey = Encryption.GetDataEncryptionKey();

            // non-web apps might not have the DataEncryptionKey, so check that first since it could happen quite a bit
            if (string.IsNullOrWhiteSpace(encryptionKey))
            {
                return(false);
            }
            else
            {
                try
                {
                    cypherText = EncryptString(plainText, encryptionKey);
                    return(true);
                }
                catch
                {
                    // intentionally ignore exception since we are a try method
                    return(false);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Encrypt the given string using AES.  The string can be decrypted using
        /// DecryptString().  The sharedSecret parameters must match.
        /// </summary>
        /// <param name="plainText">The text to encrypt.</param>
        public static string EncryptString(string plainText)
        {
            string dataEncryptionKey = Encryption.GetDataEncryptionKey();

            return(EncryptString(plainText, dataEncryptionKey));
        }