/// <summary> /// 验证签名 /// </summary> /// <param name="content"></param> /// <param name="signHex">签名字符串</param> /// <param name="publicAddress">公钥(eth地址的表达形式)</param> /// <param name="getVFunc">对V值进行自定义处理,默认V加上27</param> /// <returns></returns> public static bool Verify(byte[] content, string signHex, string publicAddress, Func <byte, byte> getVFunc = null) { byte[] md = new byte[32]; md = SHA256Hash(content); var bs = signHex.HexToByteArray(); var r_bs = new byte[32]; Array.Copy(bs, r_bs, 32); var s_bs = new byte[32]; Array.Copy(bs, 32, s_bs, 0, 32); if (getVFunc != null) { bs[64] = getVFunc(bs[64]); } else { bs[64] = (byte)(bs[64] + 27); } var signature = new EthECDSASignature(new Org.BouncyCastle.Math.BigInteger(1, r_bs), new Org.BouncyCastle.Math.BigInteger(1, s_bs), new byte[] { bs[64] }); var pubKeyObj = EthECKey.RecoverFromSignature(signature, md); var addr = pubKeyObj.GetPublicAddress(); var verifyret = pubKeyObj.Verify(md, signature); return(verifyret && string.Equals(pubKeyObj.GetPublicAddress(), publicAddress, StringComparison.OrdinalIgnoreCase)); }
public bool VerifyAllowingOnlyLowS(byte[] hash, EthECDSASignature sig) { if (!sig.IsLowS) { return(false); } return(_ecKey.Verify(hash, sig.ECDSASignature)); }
public bool Verify(byte[] hash, EthECDSASignature sig) { return(_ecKey.Verify(hash, sig.ECDSASignature)); }
public static EthECKey RecoverFromSignature(EthECDSASignature signature, byte[] hash, BigInteger chainId) { return(new EthECKey(ECKey.RecoverFromSignature(GetRecIdFromVChain(signature.V, chainId), signature.ECDSASignature, hash, false))); }
public static EthECKey RecoverFromSignature(EthECDSASignature signature, int recId, byte[] hash) { return(new EthECKey(ECKey.RecoverFromSignature(recId, signature.ECDSASignature, hash, false))); }
public static EthECKey RecoverFromSignature(EthECDSASignature signature, byte[] hash) { return(new EthECKey(ECKey.RecoverFromSignature(GetRecIdFromV(signature.V), signature.ECDSASignature, hash, false))); }