コード例 #1
0
        public static string CompressThenEncrypt(this string uncompressedString, string password)
        {
            using (MemoryStream compressedStream = new MemoryStream())
            {
                using (MemoryStream uncompressedStream = new MemoryStream(Encoding.UTF8.GetBytes(uncompressedString)))
                {
                    using (DeflateStream compressorStream = new DeflateStream(compressedStream, CompressionMode.Compress, true))
                    {
                        uncompressedStream.CopyTo(compressorStream);
                    }

                    byte[] encryptedBytes = AESGCM.SimpleEncryptWithPassword(compressedStream.ToArray(), password);

                    return(Convert.ToBase64String(encryptedBytes));
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Makes a simple password based encryption of a string and returns the result as a string
 /// <seealso cref="Decrypt(string, string)"/>
 /// </summary>
 /// <param name="unencryptedString">The string to encrypt</param>
 /// <param name="password">The password to encrypt with</param>
 /// <returns>The encrypted string</returns>
 /// <remarks>
 /// Please understand the security limitations of symmetrical encryption with a known clear-text password.
 /// </remarks>
 public static string Encrypt(this string unencryptedString, string password) => AESGCM.SimpleEncryptWithPassword(unencryptedString, password);