public static void WcfBinaryCompressedSerializeEncrypted <T1>(String dataFileName, SecureStringOrArray password, T1 objectValue) { SetupDataName(dataFileName); String dataFilePath = GetDataFilePath(dataFileName); String tempDataFilePath = SwapExtension(dataFilePath, ".tmp"); using (var stream = File.Open(tempDataFilePath, FileMode.Create)) using (DisposableAes aes = CreateCrypto(password, dataFileName)) using (CryptoStream cryptoStream = new CryptoStream( stream, aes.EncryptorTransform, CryptoStreamMode.Write)) { ServiceIo.WcfBinaryCompressedSerialize(cryptoStream, objectValue); } SafeFileMove(dataFilePath, tempDataFilePath); }
public static void BinarySerializeObjectEncrypted(String dataFileName, SecureStringOrArray password, object objectValue) { SetupDataName(dataFileName); String dataFilePath = GetDataFilePath(dataFileName); String tempDataFilePath = SwapExtension(dataFilePath, ".tmp"); using (var stream = File.Open(tempDataFilePath, FileMode.Create)) using (DisposableAes aes = CreateCrypto(password, dataFileName)) using (CryptoStream cryptoStream = new CryptoStream( stream, aes.EncryptorTransform, CryptoStreamMode.Write)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(cryptoStream, objectValue); } SafeFileMove(dataFilePath, tempDataFilePath); }
public static T1 BinaryDeserializeEncryptedObject <T1>(String dataFileName, SecureStringOrArray password) { ConvertToDCStyle(dataFileName, password); String dataFilePath = GetDataFilePath(dataFileName); using (var stream = File.Open(dataFilePath, FileMode.Open)) using (DisposableAes aes = CreateCrypto(password, dataFileName)) using (CryptoStream cryptoStream = new CryptoStream( stream, aes.DecryptorTransform, CryptoStreamMode.Read)) { BinaryFormatter formatter = new BinaryFormatter(); var result = (T1)formatter.Deserialize(cryptoStream); return(result); } }