示例#1
0
        public void EncryptDecryptFailsIfAlreadyPerformedTest()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var encrypted         = DpapiWrapper.Encrypt(message);
            var x                 = encrypted.Where(o => encrypted.Where(u => u == o).Count() > 1).First(); // find first char that appears more than once
            var y                 = encrypted.Where(o => o != x).First();                                   // find the first char not equal to x
            var tamperedEncrypted = encrypted.Replace(x, y);

            try
            {
                var decrypted = DpapiWrapper.Decrypt(tamperedEncrypted);
            }
            catch (Exception e)
            {
                e.GetType().Should().Be(typeof(System.Security.Cryptography.CryptographicException));
            }
            try
            {
                DpapiWrapper.Decrypt(message);
            }
            catch (Exception e)
            {
                e.GetType().Should().Be(typeof(ArgumentException));
            }
        }
示例#2
0
        public void EncryptDecryptTest()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var encrypted = DpapiWrapper.Encrypt(message);

            encrypted.Should().NotBeNullOrEmpty();
            encrypted.Should().NotBeNullOrWhiteSpace();
            encrypted.Should().NotBeSameAs(message);
            encrypted.Should().NotContain(message);
            DpapiWrapper.Decrypt(encrypted).Should().Be(message);
        }