public void DecryptWithDifferentEntropyThanEncryptThrows()
        {
            byte[] plainBytes = new byte[] {0, 1, 2, 3, 4};
            byte[] entropy1 = new byte[16];
            byte[] entropy2 = new byte[16];
            CryptographyUtility.GetRandomBytes(entropy1);
            CryptographyUtility.GetRandomBytes(entropy2);

            DpapiCryptographer dpapi = new DpapiCryptographer(DataProtectionScope.LocalMachine);
            byte[] encrypted = dpapi.Encrypt(plainBytes, entropy1);
            dpapi.Decrypt(encrypted, entropy2);
        }
        public void EncryptAndDecryptUserMode()
        {
            DataProtectionScope mode = DataProtectionScope.CurrentUser;
            DpapiCryptographer dpapi = new DpapiCryptographer(mode);

            byte[] cipherText = dpapi.Encrypt(plainText);

            Assert.IsFalse(CryptographyUtility.CompareBytes(plainText, cipherText));

            byte[] decryptedText = dpapi.Decrypt(cipherText);

            Assert.IsTrue(CryptographyUtility.CompareBytes(plainText, decryptedText));
        }
 public void EncryptWithZeroLengthTextThrows()
 {
     byte [] b = new byte [] {};
     DpapiCryptographer dpapi = new DpapiCryptographer(DataProtectionScope.LocalMachine);
     dpapi.Encrypt(b, entropy);
 }
 public void EncryptWithNullPlainTextThrows()
 {
     DpapiCryptographer dpapi = new DpapiCryptographer(DataProtectionScope.CurrentUser);
     dpapi.Encrypt(null);
 }