public static string SignHash(string privateKeyString, byte[] hash) { try { ECPrivateKeyParameters privateKeyParameters = EosKeyHelper.GetECPrivateKeyParametersFromString(privateKeyString); ISigner signer = SignerUtilities.GetSigner("NONEwithECDSA"); signer.Init(true, privateKeyParameters); signer.BlockUpdate(hash, 0, hash.Length); byte[] sigBytes = signer.GenerateSignature(); var check = new List <byte[]>() { sigBytes, KEY_TYPE_BYTES }; var checksum = Ripemd160Manager.GetHash(SerializationHelper.Combine(check)).Take(CHECKSUM_LENGHT).ToArray(); var signAndChecksum = new List <byte[]>() { sigBytes, checksum }; var finalSig = SIG_PREFIX + Base58.Encode(SerializationHelper.Combine(signAndChecksum)); return(finalSig); } catch (Exception exc) { Console.WriteLine("Signing Failed: " + exc.ToString()); return(null); } }
public static bool VerifySignature(string publicKeyString, string signature, byte[] hash) { try { byte[] sigBytes = GetSignatureBytesWithoutCheckSum(signature); var publicKeyParameters = EosKeyHelper.GetECPublicKeyParametersFromString(publicKeyString); ISigner signer = SignerUtilities.GetSigner("NONEwithECDSA"); signer.Init(false, publicKeyParameters); signer.BlockUpdate(hash, 0, hash.Length); return(signer.VerifySignature(sigBytes)); } catch (Exception exc) { Console.WriteLine("Verification failed with the error: " + exc.ToString()); return(false); } }