Пример #1
0
        public void DataSignAndVerify()
        {
            // Arrange
            var privateKey  = HexMate.Convert.FromHexString(PrivateKeys[1]);
            var messageData = MessageData[1];

            Console.WriteLine("Input:");
            Console.WriteLine("Private Key: [{0}] {1}", privateKey.Length, HexMate.Convert.ToHexString(privateKey));
            Console.WriteLine("MessageData: [{0}] {1}", messageData.Length, HexMate.Convert.ToHexString(messageData));

            // Act
            var parameters = new BLSParameters()
            {
                PrivateKey = privateKey
            };

            using var bls = new BLSHerumi(parameters);

            var publicKey = new byte[48];

            _ = bls.TryExportBlsPublicKey(publicKey, out var _);

            Console.WriteLine("Public Key: [{0}] {1}", publicKey.Length, HexMate.Convert.ToHexString(publicKey));

            var signature        = new byte[96];
            var signatureSuccess = bls.TrySignData(messageData, signature.AsSpan(), out var bytesWritten);

            Console.WriteLine("Signature: {0} [{1}] {2}", signatureSuccess, bytesWritten, HexMate.Convert.ToHexString(signature));

            var verifySuccess = bls.VerifyData(messageData, signature);

            Console.WriteLine("Verify1: {0}", verifySuccess);

            var parameters2 = new BLSParameters()
            {
                PublicKey = publicKey
            };

            using var bls2 = new BLSHerumi(parameters);

            var verifySuccess2 = bls2.VerifyData(messageData, signature);

            Console.WriteLine("Verify2: {0}", verifySuccess2);

            verifySuccess2.ShouldBeTrue();
        }
Пример #2
0
        public void Verify(string testName, byte[] publicKey, byte[] messageData, byte[] signature, bool expected)
        {
            // Arrange
            var parameters = new BLSParameters()
            {
                PublicKey = publicKey
            };

            Console.WriteLine("Input:");
            Console.WriteLine("Public Key: [{0}] {1}", publicKey.Length, HexMate.Convert.ToHexString(publicKey));
            Console.WriteLine("MessageHash: [{0}] {1}", messageData.Length, HexMate.Convert.ToHexString(messageData));
            Console.WriteLine("Signature: [{0}] {1}", signature.Length, HexMate.Convert.ToHexString(signature));

            // Act
            using var bls = new BLSHerumi(parameters);
            var success = bls.VerifyData(messageData, signature);

            Console.WriteLine("Output: Success {0}", success);

            // Assert
            success.ShouldBe(expected);
        }