コード例 #1
0
        public void ShouldComputeDifferentEntropyForDifferentInstitutionAndGroup()
        {
            const string institution = "some inst";
            const string group       = "group";
            const string product     = "Ovation";

            const string institution2 = "other inst";
            const string group2       = "group2";

            var repo = new FileSystemKeyRepository();

            Assert.NotEqual(repo.EntropyBytes(institution2, group2, product),
                            repo.EntropyBytes(institution, group, product));
        }
コード例 #2
0
        public void ShouldComputeDifferentEntropyForDifferentInstitutionAndGroup()
        {
            const string institution = "some inst";
            const string group = "group";
            const string product = "Ovation";

            const string institution2 = "other inst";
            const string group2 = "group2";

            var repo = new FileSystemKeyRepository();

            Assert.NotEqual(repo.EntropyBytes(institution2, group2, product),
                repo.EntropyBytes(institution, group, product));
        }
コード例 #3
0
        private static string ReadKey(FileSystemKeyRepository repo, string institution, string group, string product)
        {
            var keyName = String.Format("{0}__{1}__{2}", institution, group, product);

            using (var stream = new FileStream(
                       Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", keyName),
                       FileMode.Open,
                       FileAccess.Read))
                using (var reader = new BinaryReader(stream))
                {
                    var encryptedBytes = reader.ReadBytes((int)stream.Length);
                    var bytes          = ProtectedData.Unprotect(encryptedBytes,
                                                                 repo.EntropyBytes(institution, group, product),
                                                                 DataProtectionScope.CurrentUser);

                    return(Encoding.UTF8.GetString(bytes));
                }
        }
コード例 #4
0
        public void ShouldWriteEntropyToFile()
        {
            const string institution = "Some Institution";
            const string group       = "Some Group";
            const string product     = "Some Product";

            var repo = new FileSystemKeyRepository();

            var entropyBytes = repo.EntropyBytes(institution, group, product);

            var entropyFileName = String.Format("entropy_{0}__{1}__{2}", institution, group, product);

            using (var stream = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", entropyFileName),
                                               FileMode.Open,
                                               FileAccess.Read)
                   )
                using (var reader = new BinaryReader(stream))
                {
                    var fileBytes = reader.ReadBytes((int)stream.Length);
                    Assert.Equal(entropyBytes, fileBytes);
                }
        }
コード例 #5
0
        public void ShouldWriteEntropyToFile()
        {
            const string institution = "Some Institution";
            const string group = "Some Group";
            const string product = "Some Product";

            var repo = new FileSystemKeyRepository();

            var entropyBytes = repo.EntropyBytes(institution, group, product);

            var entropyFileName = String.Format("entropy_{0}__{1}__{2}", institution, group, product);

            using(var stream = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", entropyFileName),
                FileMode.Open,
                FileAccess.Read)
                )
            using (var reader = new BinaryReader(stream))
            {
                var fileBytes = reader.ReadBytes((int)stream.Length);
                Assert.Equal(entropyBytes, fileBytes);
            }
        }
コード例 #6
0
        private static string ReadKey(FileSystemKeyRepository repo, string institution, string group, string product)
        {
            var keyName = String.Format("{0}__{1}__{2}", institution, group, product);

            using(var stream = new FileStream(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Physion", "Ovation", "keys", keyName),
                FileMode.Open,
                FileAccess.Read))
            using (var reader = new BinaryReader(stream))
            {
                var encryptedBytes = reader.ReadBytes((int)stream.Length);
                var bytes = ProtectedData.Unprotect(encryptedBytes,
                    repo.EntropyBytes(institution, group, product),
                    DataProtectionScope.CurrentUser);

                return Encoding.UTF8.GetString(bytes);
            }
        }