private void BasicSigTest() { Ed448PrivateKeyParameters privateKey = new Ed448PrivateKeyParameters( Hex.DecodeStrict( "6c82a562cb808d10d632be89c8513ebf" + "6c929f34ddfa8c9f63c9960ef6e348a3" + "528c8a3fcc2f044e39a3fc5b94492f8f" + "032e7549a20098f95b"), 0); Ed448PublicKeyParameters publicKey = new Ed448PublicKeyParameters( Hex.DecodeStrict("5fd7449b59b461fd2ce787ec616ad46a" + "1da1342485a70e1f8a0ea75d80e96778" + "edf124769b46c7061bd6783df1e50f6c" + "d1fa1abeafe8256180"), 0); byte[] sig = Hex.DecodeStrict("533a37f6bbe457251f023c0d88f976ae" + "2dfb504a843e34d2074fd823d41a591f" + "2b233f034f628281f2fd7a22ddd47d78" + "28c59bd0a21bfd3980ff0d2028d4b18a" + "9df63e006c5d1c2d345b925d8dc00b41" + "04852db99ac5c7cdda8530a113a0f4db" + "b61149f05a7363268c71d95808ff2e65" + "2600"); ISigner signer = new Ed448Signer(new byte[0]); signer.Init(true, privateKey); IsTrue(AreEqual(sig, signer.GenerateSignature())); signer.Init(false, publicKey); IsTrue(signer.VerifySignature(sig)); }
/// <summary> /// Signs the passed in data with a private key /// </summary> /// <param name="privateKey">the private key used to create the signature</param> /// <param name="data">The data to sign</param> /// <returns>the signature as a byte array</returns> public byte[] Sign(byte[] privateKey, byte[] data) { var signer = new Ed448Signer(ByteConvert.StringToAsciiBytes("context")); Ed448PrivateKeyParameters privKey = null; try { privKey = (Ed448PrivateKeyParameters)CreateAsymmetricKeyParameterFromPrivateKeyInfo(privateKey); } catch (InvalidCastException exception) { string message = "Private Key Import Failed!\n" + $"{exception.Message}.\n" + "The contents of the source do not represent a valid Ed448 key parameter\n" + "Verify that the key is not corrupted.\n" + "- or - Verify that the correct key is selected."; throw new CryptoException(message, exception); } signer.Init(true, privKey); signer.BlockUpdate(data, 0, data.Length); var signature = signer.GenerateSignature(); return(signature); }