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 DefaultStorageMode()
 {
     DpapiCryptographer dpapi = new DpapiCryptographer();
     Assert.AreEqual(DataProtectionScope.LocalMachine, dpapi.StoreScope);
 }
 public void DecryptWithNullCipherTextThrows()
 {
     DpapiCryptographer dpapi = new DpapiCryptographer(DataProtectionScope.CurrentUser);
     dpapi.Decrypt(null);
 }
 public void DecryptWithEmptyCipherTextThrows()
 {
     byte[] b = new byte[] { };
     DpapiCryptographer dpapi = new DpapiCryptographer(DataProtectionScope.CurrentUser);
     dpapi.Decrypt(b);
 }
 public void DecryptBadDataThrows()
 {
     DpapiCryptographer dpapi = new DpapiCryptographer();
     byte[] cipherText = new byte[] {0, 1};
     dpapi.Decrypt(cipherText, entropy);
 }
 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);
 }