Пример #1
0
        public void Init()
        {
            var encryptorDecryptor = new AesEncryptorDecryptor();
            var headerGenerator    = new ShaHeaderGenerator();

            _encryptor = new ShaAesEncryptor(encryptorDecryptor, headerGenerator);
            _decryptor = new ShaAesDecryptor(encryptorDecryptor, headerGenerator);
        }
        public async Task SerializeDeserialize()
        {
            const string toEncryptAndSerialize = "something to encrypt and serialize";

            var encryptorDecryptor = new AesEncryptorDecryptor();
            var headerGenerator    = new ShaHeaderGenerator();
            var serializer         = new EncryptionSerializer <string>(new JsonSerializer <string>(), new ShaAesEncryptor(encryptorDecryptor, headerGenerator), new ShaAesDecryptor(encryptorDecryptor, headerGenerator), "sample passphrase".ToSecureString(), "sample salt");

            using (var memoryStream = new MemoryStream())
            {
                await serializer.SerializeAsync(memoryStream, toEncryptAndSerialize);

                memoryStream.Position = 0;

                var actual = await serializer.DeserializeAsync(memoryStream);

                Assert.That(actual, Is.EqualTo(toEncryptAndSerialize));
            }
        }