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")); } }
//signs a message using the internal private and public keys public string SignMessage(string message) { RLWEParameters mpar = RLWEParamSets.RLWEN512Q12289; string signature = ""; using (RLWESign sgn = new RLWESign(mpar)) { sgn.Initialize(_privateKey.Key); byte[] messageBytes = Encoding.UTF8.GetBytes(message); byte[] signatureBytes = sgn.Sign(messageBytes, 0, messageBytes.Length); signature = Convert.ToBase64String(signatureBytes); } return(signature); }
//signs a message using the private and public keys provided public string SignMessage(string message, IPrivateKey privateKey, IPublicKey publicKey = null) { //NB: public key isn't required by this implementation, so is initialized to null RLWEParameters mpar = RLWEParamSets.RLWEN512Q12289; string signature = ""; using (RLWESign sgn = new RLWESign(mpar)) { sgn.Initialize(((PrivateKey)(privateKey)).Key); byte[] messageBytes = Encoding.UTF8.GetBytes(message); byte[] signatureBytes = sgn.Sign(messageBytes, 0, messageBytes.Length); signature = Convert.ToBase64String(signatureBytes); } return(signature); }