Esempio n. 1
0
        private void TestSign()
        {
            RLWEParameters     mpar  = RLWEParamSets.RLWEN512Q12289;
            RLWEKeyGenerator   mkgen = new RLWEKeyGenerator(mpar);
            IAsymmetricKeyPair akp   = mkgen.GenerateKeyPair();

            using (RLWESign sgn = new RLWESign(mpar))
            {
                sgn.Initialize(akp.PublicKey);

                int    sz   = sgn.MaxPlainText;
                byte[] data = new byte[200];
                new VTDev.Libraries.CEXEngine.Crypto.Prng.CSPRng().GetBytes(data);

                byte[] code = sgn.Sign(data, 0, data.Length);

                sgn.Initialize(akp.PrivateKey);
                if (!sgn.Verify(data, 0, data.Length, code))
                {
                    throw new Exception("EncryptionKey: private key comparison test failed!");
                }
                OnProgress(new TestEventArgs("Passed byte sign and verify"));

                sgn.Initialize(akp.PublicKey);
                code = sgn.Sign(new MemoryStream(data));

                sgn.Initialize(akp.PrivateKey);
                if (!sgn.Verify(new MemoryStream(data), code))
                {
                    throw new Exception("EncryptionKey: private key comparison test failed!");
                }
                OnProgress(new TestEventArgs("Passed stream sign and verify"));
            }
        }
Esempio n. 2
0
        //verify provided message with the signature and public key provided
        public bool VerifySignature(string message, string signature, IPublicKey publicKey)
        {
            bool result = false;

            RLWEParameters mpar = RLWEParamSets.RLWEN512Q12289;

            using (RLWESign sgn = new RLWESign(mpar))
            {
                sgn.Initialize(((PublicKey)publicKey).Key);
                byte[] messageBytes   = Encoding.UTF8.GetBytes(message);
                byte[] signatureBytes = Convert.FromBase64String(signature);

                result = sgn.Verify(messageBytes, 0, messageBytes.Length, signatureBytes);
            }

            return(result);
        }