Exemplo n.º 1
0
        public void AppPasswordEncryptDecryptTest()
        {
            SecureString masterPassword, appPassword;

            GetPasswords(out masterPassword, out appPassword);
            Crypto.Crypto crypto = new Crypto.Crypto();

            var          result           = crypto.EncryptAppPassword(appPassword, masterPassword);
            SecureString decryptedPassord = crypto.DecryptAppPassword(result.Item1, _appPasswordArray.Length, masterPassword, result.Item2);

            Assert.AreEqual(GetSecureStringValue(appPassword), GetSecureStringValue(decryptedPassord));
        }
Exemplo n.º 2
0
        public async Task EncryptDecryptDataArrayTest()
        {
            byte[] bytes = new byte[_data.Length * sizeof(char)];
            Buffer.BlockCopy(_data.ToCharArray(), 0, bytes, 0, bytes.Length);
            SecureString masterPassword, appPassword;

            GetPasswords(out masterPassword, out appPassword);

            Crypto.Crypto crypto          = new Crypto.Crypto();
            var           appPasswordData = crypto.EncryptAppPassword(appPassword, masterPassword);

            byte[] encryptedResult = await crypto.EncryptDataArrayAsync(bytes, appPassword, appPasswordData.Item2);

            MemoryStream ms = new MemoryStream();

            ms.Write(encryptedResult, 0, encryptedResult.Length);
            ms.Position = 0;
            byte[] decryptedResult = crypto.DecryptMemoryStream(ms, appPassword, appPasswordData.Item2);
            Assert.IsTrue(bytes.Length == decryptedResult.Length && bytes.OrderBy(s => s).SequenceEqual(decryptedResult.OrderBy(s => s)));

            decryptedResult = await crypto.DecryptMemoryStreamAsync(ms, appPassword, appPasswordData.Item2);

            Assert.IsTrue(bytes.Length == decryptedResult.Length && bytes.OrderBy(s => s).SequenceEqual(decryptedResult.OrderBy(s => s)));
        }