Пример #1
0
        public void RoundTrip_Protect()
        {
            // Roundtrip a message using DPAPI protection

            const string message      = "The dog jumped over the fence #@//\\\\$";
            var          messageBytes = Encoding.ASCII.GetBytes(message);

            var protectedBytes   = DPAPI.ProtectData(messageBytes, true);
            var unProtectedBytes = DPAPI.UnProtectData(protectedBytes, true);

            Assert.AreEqual(messageBytes, unProtectedBytes);
        }
Пример #2
0
 /// <summary>
 ///     Encrypt and save a security token
 /// </summary>
 /// <param name="filePath">The path to the file where the security token should be stored</param>
 /// <param name="token">The security token to encrypt and save</param>
 private static void SetSecurityToken(string filePath, byte[] token)
 {
     try
     {
         token = DPAPI.ProtectData(token, true);
         File.WriteAllBytes(filePath, token);
     }
     catch (Exception ex)
     {
         Log.Error(LogName, "Could not save security token");
         Log.Error(LogName, ex);
     }
 }
Пример #3
0
 public void NullProtect()
 {
     Assert.Throws <ArgumentNullException>(() => DPAPI.ProtectData(null, true));
 }