static void Main(string[] args) { ECKeyPair keyPair = KeyPairGenerator.Generate(); //Console.WriteLine(privateKey.ToString() + Environment.NewLine); // Fake data byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").ToByteArray(); ECSigner signer = new ECSigner(); ECSignature signature = signer.Sign(keyPair, message); message = new BigInteger("9682368737159881417056907351531570756676647951").ToByteArray(); ECVerifier verifier = new ECVerifier(keyPair); bool isGood = verifier.Verify(signature, message); Console.WriteLine(isGood); }
public override byte[] ProcessBlock( byte[] @in, int inOff, int inLen) { if (ForEncryption) { if (KeyPairGenerator != null) { EphemeralKeyPair ephKeyPair = KeyPairGenerator.Generate(); PrivParam = ephKeyPair.GetKeyPair().Private; V = ephKeyPair.GetEncodedPublicKey(); } } else { if (KeyParser != null) { MemoryStream bIn = new MemoryStream(@in, inOff, inLen) { Position = SecureHeadSize }; try { PubParam = KeyParser.ReadKey(bIn); } catch (IOException e) { throw new InvalidCipherTextException("unable to recover ephemeral public key: " + e.Message, e); } catch (ArgumentException e) { throw new InvalidCipherTextException("unable to recover ephemeral public key: " + e.Message, e); } int encLength = (inLen - (int)(bIn.Length - bIn.Position)); V = Arrays.CopyOfRange(@in, inOff + SecureHeadSize, inOff + encLength); } } // Compute the common value and convert to byte array. Agree.Init(PrivParam); BigInteger z = Agree.CalculateAgreement(PubParam); byte[] bigZ = BigIntegers.AsUnsignedByteArray(Agree.GetFieldSize(), z); try { // Initialise the KDF. KdfParameters kdfParam = new KdfParameters(bigZ, null); Kdf.Init(kdfParam); if (ForEncryption) { return(EncryptBlock(@in, inOff, inLen)); } else { byte[] temp = new byte[inLen - SecureHeadSize]; Array.Copy(@in, inOff + SecureHeadSize, temp, 0, temp.Length); return(DecryptBlock(temp, inOff, temp.Length)); } } finally { Arrays.Fill(bigZ, 0); } }