private StreamWriter GetEncryptedStreamWriter(string fileFullPath) { SafeDirectoryGenerator.GenerateDirectory(fileFullPath); var underlyingStream = new FileStream(fileFullPath, FileMode.OpenOrCreate); var rijndael = Rijndael.Create(); var encryptInfo = EncryptManager.CreateEncryptInfo(); rijndael.Key = encryptInfo.Key; rijndael.IV = encryptInfo.Iv; // ファイルの先頭に初期ベクトルを追加 underlyingStream.Write(encryptInfo.Iv, 0, encryptInfo.Iv.Length); var encryptedStream = new CryptoStream(underlyingStream, rijndael.CreateEncryptor(), CryptoStreamMode.Write); return(new StreamWriter(encryptedStream)); }
private StreamReader GetEncryptedStreamReader(string fileFullPath) { SafeDirectoryGenerator.GenerateDirectory(fileFullPath); var underlyingStream = new FileStream(fileFullPath, FileMode.Open); byte[] iv = new byte[EncryptManager.IV_LENGTH]; // ファイルの先頭から初期ベクトルを取得 underlyingStream.Read(iv, 0, EncryptManager.IV_LENGTH); var rijndael = Rijndael.Create(); var encryptInfo = EncryptManager.CreateEncryptInfo(); rijndael.Key = encryptInfo.Key; rijndael.IV = iv; var encryptedStream = new CryptoStream(underlyingStream, rijndael.CreateDecryptor(), CryptoStreamMode.Read); return(new StreamReader(encryptedStream)); }
private StreamReader GetStreamReader(string fileFullPath) { SafeDirectoryGenerator.GenerateDirectory(fileFullPath); return(new StreamReader(new FileStream(fileFullPath, FileMode.Open))); }