Ejemplo n.º 1
0
        /// <summary>
        /// Get a clear text or encoded string.
        /// </summary>
        /// <param name="text">A text string to encrypt or decrypt.</param>
        /// <param name="encryptOrDecrypt">Whether we are encrypting or decrypting.</param>
        /// <param name="method">Whether we are encoding or decoding.</param>
        /// <returns>The resulting encrypted/decrypted encoded/decoded string.</returns>
        public string GetString(string text, Action encryptOrDecrypt, EncodingMethod method)
        {
            AesManaged aes = this.Crypto;

            byte[] resultArray = this.GetBytes(text, encryptOrDecrypt);
            string resultString;

            switch (method)
            {
            case EncodingMethod.Base64:
                resultString = Convert.ToBase64String(resultArray);
                break;

            case EncodingMethod.Base32:
                resultString = Base32.ToBase32String(resultArray);
                break;

            case EncodingMethod.Base16:
                resultString = Base16.ToBase16String(resultArray);
                break;

            default:
                resultString = Encoding.Unicode.GetString(resultArray);
                break;
            }

            return(resultString);
        }