Exemplo n.º 1
0
        public static string GetDatabaseKey()
        {
            if (Program.AppEnvDebug)
            {
                return("");
            }

            var keyPath = Config.GetDatabaseKeyPath();

            string databaseKey;

            if (!File.Exists(keyPath))
            {
                // Need to create a new key
                databaseKey = RandomUtil.GenerateDatabaseKey();
                var encryptedKey = UserDataProtection.Protect(databaseKey);
                File.WriteAllText(keyPath, encryptedKey);
            }
            else
            {
                var encryptedKey = File.ReadAllText(keyPath);
                databaseKey = UserDataProtection.Unprotect(encryptedKey);
            }

            return(databaseKey);
        }
Exemplo n.º 2
0
        public void GenerateDatabaseKey()
        {
            var randomString1 = RandomUtil.GenerateDatabaseKey();
            var randomString2 = RandomUtil.GenerateDatabaseKey();

            Assert.That(randomString1, Is.Not.Empty);
            Assert.That(randomString2, Is.Not.Empty);
            Assert.That(randomString1, Is.Not.EqualTo(randomString2));
        }