Beispiel #1
0
        public void TestSerialize()
        {
            ECKeyValidator    keyValidator = new ECKeyValidator();
            var               priv_key     = keyValidator.RSA.ToXmlString(true);
            var               pub_key      = keyValidator.RSA.ToXmlString(false);
            var               sign         = keyValidator.SignData("messadhgdhdhh");
            SignatureEvidence rawSign      = new SignatureEvidence(new HexString(Serializer.ToBinaryArray(sign)),
                                                                   new HexString(Serializer.ToBinaryArray(pub_key)));
            ITransactionRepository subscr    = new TransactionRepository();
            TransactionValidator   validator = new TransactionValidator();
            var byteSign = validator.SerializeSignature(rawSign);

            byte[] bytePrivKey = null, bytePubKey = null;
            using (MemoryStream stream1 = new MemoryStream(byteSign))
            {
                using (BinaryReader reader = new BinaryReader(stream1)) {
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    bytePubKey  = reader.ReadBytes(243);
                    bytePrivKey = reader.ReadBytes(178);
                }
            }

            var pub  = Serializer.ToBinaryArray(pub_key);
            var priv = Serializer.ToBinaryArray(sign);

            Assert.ReferenceEquals(pub, bytePubKey);
        }
Beispiel #2
0
        public void TestECK()
        {
            ECKeyValidator key        = new ECKeyValidator();
            string         publicKey  = key.RSA.ToXmlString(false);
            string         privateKey = key.RSA.ToXmlString(true);

            string plainText = "originalMessage";
            // string tamperMessage = "origiinalMessage";

            string signedMessage = key.SignData(plainText);

            Assert.IsTrue(key.VerifyMessage(plainText, signedMessage, publicKey));
        }