예제 #1
0
        public void OnSecretSplit_FlagsShouldBeTrue()
        {
            var splitter = new SecretSplittingProvider(Message, RandBytes);
            splitter.SplitSecretBetweenTwoPeople();

            Assert.IsTrue(splitter.IsRProtected);
            Assert.IsTrue(splitter.IsSProtected);
            Assert.IsTrue(splitter.IsSecretMessageProtected);
        }
예제 #2
0
        /// <summary>
        /// Provide toggling of memory protection for instances of SecretSplittingProvider
        /// </summary>
        /// <param name="instance"></param>
        public static void ToggleMemoryProtection(SecretSplittingProvider instance)
        {
            if (!instance.IsSecretMessageProtected)
            {
                try
                {
                    ProtectedMemory.Protect(instance.SecretMessage, MemoryProtectionScope.SameProcess);
                    ProtectedMemory.Protect(instance.R, MemoryProtectionScope.SameProcess);
                    ProtectedMemory.Protect(instance.S, MemoryProtectionScope.SameProcess);

                    instance.IsSecretMessageProtected = true;
                }
                catch (CryptographicException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }
            else
            {
                try
                {
                    ProtectedMemory.Unprotect(instance.SecretMessage, MemoryProtectionScope.SameProcess);
                    ProtectedMemory.Unprotect(instance.R, MemoryProtectionScope.SameProcess);
                    ProtectedMemory.Unprotect(instance.S, MemoryProtectionScope.SameProcess);

                    instance.IsSecretMessageProtected = false;
                }
                catch (CryptographicException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }
        }