Пример #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>
        /// </summary>
        /// <param name="filePath">The path to the file where the security token is stored</param>
        /// <returns>The decrypted security token</returns>
        private static byte[] GetSecurityToken(string filePath)
        {
            try
            {
                if (!File.Exists(filePath))
                {
                    Log.Warn(LogName, $"No token found at {filePath}, this is expected if the client has not authenticated before");
                }
                var token = File.ReadAllBytes(filePath);
                token = DPAPI.UnProtectData(token, true);
                return(token);
            }
            catch (Exception ex)
            {
                Log.Error(LogName, "Could not get security token");
                Log.Error(LogName, ex);
            }

            return(System.Text.Encoding.ASCII.GetBytes("NoToken"));
        }
Пример #3
0
 public void NullUnProtect()
 {
     Assert.Throws <ArgumentNullException>(() => DPAPI.UnProtectData(null, true));
 }