Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
                    }
        }