예제 #1
0
        public static void TestCommutative()
        {
            var rsa        = new RSACryptography();
            var privateKey = rsa.KeyCreator.CreatePrivateKey();
            var publicKey  = rsa.KeyCreator.CreatePublicKey(privateKey);
            var blindKey   = rsa.KeyCreator.CreateBlindKey();
            var msg        = Encoding.UTF7.GetBytes("sdlfjsf;slkfslkfddfshkfksjfhsjhfsjldfslkjfslakddsfklsjdflsdkfjsjgakdglkjjkdfhgdkjfghlskdhgklshdglsjdfhgjshfjsdhfkshfsdgfjshgfasldhalskdjalskfsdhjkfsdhfgsfkjaghsjlkfhasdohdfgskljafskhfgkflsdjfkljnzjzzmnznzzzzzzzzzzzzzz");

            Console.WriteLine(Encoding.UTF7.GetString(msg));
            var encrypted = rsa.Encrypt(publicKey, msg);
            var decrypted = rsa.Decrypt(privateKey, encrypted);

            Console.WriteLine(Encoding.UTF7.GetString(decrypted));

            var B          = Encoding.UTF8.GetBytes("B");
            var blindB     = rsa.BlindData(blindKey, publicKey, B);
            var signB      = rsa.SignData(privateKey, B);
            var signBlindB = rsa.SignData(privateKey, blindB);
            var blindSignB = rsa.BlindData(blindKey, publicKey, signB);

            Console.WriteLine($"Commutative = {signBlindB.SequenceEqual(blindSignB)}");
            Console.WriteLine($"Verify test = {rsa.VerifyData(publicKey, B, signB)}");
        }
예제 #2
0
        public static void TestBlind()
        {
            var rsa         = new RSACryptography();
            var blindKey    = rsa.KeyCreator.CreateBlindKey();
            var privateKey  = rsa.KeyCreator.CreatePrivateKey();
            var privateKey1 = rsa.KeyCreator.CreatePrivateKey();
            var publicKey   = rsa.KeyCreator.CreatePublicKey(privateKey);
            var publicKey1  = rsa.KeyCreator.CreatePublicKey(privateKey1);


            var B             = Encoding.UTF8.GetBytes("B");
            var blinded       = rsa.BlindData(blindKey, publicKey, B);
            var blindSigned   = rsa.SignData(privateKey, blinded);
            var unblindSigned = rsa.UnBlindData(blindKey, publicKey, blindSigned);

            Console.WriteLine($"Verified? = {rsa.VerifyData(publicKey, B, unblindSigned)}");
        }