クラスオブジェクトをファイルに保存し、開いたキーと閉じたキーで暗号化する方法。
閉じたキーはすべてに1つである必要があります(安全のために)
オープンキーはファイルごとに異なる必要があります。
このコードを使用したい...それが私が望むもののように見えますが、それでも暗号化が必要です。
public ObjectToFile(_Object : object, _FileName : string) : bool
{
try
{
// create new memory stream
mutable _MemoryStream : System.IO.MemoryStream = System.IO.MemoryStream();
// create new BinaryFormatter
def _BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
= System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// Serializes an object, or graph of connected objects, to the given stream.
_BinaryFormatter.Serialize(_MemoryStream, _Object);
// convert stream to byte array
mutable _ByteArray : array[byte] = _MemoryStream.ToArray();
// Open file for writing
def _FileStream : System.IO.FileStream =
System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
// Writes a block of bytes to this stream using data from a byte array.
_FileStream.Write(_ByteArray, 0, _ByteArray.Length);
// close file stream
_FileStream.Close();
// cleanup
_MemoryStream.Close();
_MemoryStream.Dispose();
_MemoryStream = null;
_ByteArray = null;
true
}
catch
{
| e is Exception => // Error
{
Console.WriteLine("Exception caught in process: {0}", e.ToString());
false
}
}
}
モデレーターへ:C#タグを削除しないでください。これは、C#の回答を取得でき、nemerleの回答を取得する可能性が低いためです:)