Exemplo n.º 1
0
        public void SignAndVerifyWithPem()
        {
            var data = "NewLife".GetBytes();

            Byte[] sign;

            {
                var ec = ECDsaHelper.Create(prvKey);

                var key = ec.Key.Export(CngKeyBlobFormat.EccPrivateBlob).ToBase64();
                Assert.Equal("RUNTMiAAAAARWz+jn65BtOMvdyHKcvjBeBSDZH2r1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087GevZzL1gdAFr88hb2OF/2NxApJCzGCEDdfSp6VQO30hw=", key);

                sign = ec.SignData(data);
            }

            {
                var ec = ECDsaHelper.Create(pubKey);

                var key = ec.Key.Export(CngKeyBlobFormat.EccPublicBlob).ToBase64();
                Assert.Equal("RUNTMSAAAAARWz+jn65BtOMvdyHKcvjBeBSDZH2r1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G", key);

                var rs = ec.VerifyData(data, sign);
                Assert.True(rs);
            }
        }
Exemplo n.º 2
0
        public void TestPrivatePem()
        {
            var ec = ECDsaHelper.Create(prvKey);

            var key = ec.Key.Export(CngKeyBlobFormat.EccPrivateBlob).ToBase64();

            Assert.Equal("RUNTMiAAAAARWz+jn65BtOMvdyHKcvjBeBSDZH2r1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087GevZzL1gdAFr88hb2OF/2NxApJCzGCEDdfSp6VQO30hw=", key);

            //var sign = ec.SignData("NewLife".GetBytes());
            //Assert.Equal("9rW9GddDi0jjVMnbAulgqiPpXQJR3oJIz/XX9mYVI9uIMePlmW9eNbwdq34AMFa5pp31513AR2WxQ1Nz6K2aZQ==", sign.ToBase64());
        }
Exemplo n.º 3
0
        public void TestPublicPem()
        {
            var ec = ECDsaHelper.Create(pubKey);

            var key = ec.Key.Export(CngKeyBlobFormat.EccPublicBlob).ToBase64();

            Assert.Equal("RUNTMSAAAAARWz+jn65BtOMvdyHKcvjBeBSDZH2r1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G", key);

            //var rs = ec.VerifyData("NewLife".GetBytes(), "9rW9GddDi0jjVMnbAulgqiPpXQJR3oJIz/XX9mYVI9uIMePlmW9eNbwdq34AMFa5pp31513AR2WxQ1Nz6K2aZQ==".ToBase64());
            //Assert.True(rs);
        }
Exemplo n.º 4
0
        public void Create()
        {
            var ks = ECDsaHelper.GenerateKey();

            var ec = ECDsaHelper.Create(ks[0]);

            Assert.NotNull(ec);

            var ec2 = ECDsaHelper.Create(prvKey);

            Assert.NotNull(ec2);

            var ec3 = ECDsaHelper.Create(pubKey);

            Assert.NotNull(ec3);
        }