VB.NET
' Rijndaelを利用してファイル内の文字列を暗号化する方法
Using fStream = File.Open("encrypted.txt", FileMode.OpenOrCreate)
Dim RijndaelAlg As Rijndael = Rijndael.Create
Using cStream As New CryptoStream(fStream,RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV),CryptoStreamMode.Write)
Using sWriter As New StreamWriter(cStream)
sWriter.WriteLine("Text to encrypt")
End Using
End Using
End Using
C#
// Rijndaelを利用してファイル内の文字列を暗号化する方法
{
using (fStream == File.Open("encrypted.txt", FileMode.OpenOrCreate)) {
Rijndael RijndaelAlg = Rijndael.Create;
using (CryptoStream cStream = new CryptoStream(fStream, RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), CryptoStreamMode.Write)) {
using (StreamWriter sWriter = new StreamWriter(cStream)) {
sWriter.WriteLine("Text to encrypt");
}
}
}
}