public void DataProtectorWithDifferentEntropy_CannotDecrypt()
        {
            var entropy2   = new byte[] { 7, 8, 9, 10 };
            var protector2 = new DataProtector(entropy2);

            var cypher = _sut.Protect(_userData);

            Assert.Throws <CryptographicException>(() => protector2.Unprotect(cypher));
        }
        static string ManuallyDecrypt(string encryptedString, IEnumerable<string> purposes = null)
        {
            var entropyCreator = new EntropyCreator();
              var entropy = entropyCreator.CreateEntropy(purposes);
              var protector = new DataProtector(entropy);

              var cypher = Convert.FromBase64String(encryptedString);
              var userData = protector.Unprotect(cypher);

              return Encoding.UTF8.GetString(userData);
        }
 public virtual void SetUp()
 {
     _entropy  = new byte[] { 1, 2, 3 };
     _userData = new byte[] { 4, 5, 6 };
     _sut      = new DataProtector(_entropy);
 }
        public void ConstructWithNullEntropy_IsAllowed()
        {
            var actual = new DataProtector(null);

            Assert.That(actual, Is.Not.Null);
        }
        static string ManuallyEncrypt(string stringtoEncrypt, IEnumerable<string> purposes = null)
        {
            var entropyCreator = new EntropyCreator();
              var entropy = entropyCreator.CreateEntropy(purposes);
              var protector = new DataProtector(entropy);

              var userData = Encoding.UTF8.GetBytes(stringtoEncrypt);
              var cypher = protector.Protect(userData);

              return Convert.ToBase64String(cypher);
        }