我正在使用 NBitcoin nuget 包。我尝试创建私钥和公钥(地址)。之后,我尝试签署一些消息,然后使用 pub 密钥验证此签名。但是 NBitcoin ,用于使用具有私钥对象的 BitcoinSecret 对象进行验证。那么,为什么要使用这个对象来验证 NBitcoin?我如何在没有私钥的情况下验证签名,只使用地址(pubKey)、签名和消息?谢谢
static void Main(string[] args)
{
Key Key = new Key(); //Create private key
//We can take private key
var privateKey = Key.GetBitcoinSecret(Network.Main);
//Get the public key, and derive the address on the Main network
BitcoinAddress address = privateKey.PubKey.GetAddress(Network.Main);
For the sign to data , create secret object.
BitcoinSecret secret = new BitcoinSecret(Key, Network.Main);
string message = $"I am Nicolas";
Console.WriteLine("Message:" + message + "\n");
sign message with private key.
string signature = secret.PrivateKey.SignMessage(message);
Console.WriteLine("Signature:" + signature + "\n");
/* Now I dont understand this code. For the verify , I know that we need
to signature message , message and pub or adres value.\n But in this code using
again private secret object which has got private key. How we can verify
signature messaga with pub or address and message (dont include private key)*/
if (secret.PubKey.VerifyMessage(message, signature))
{
Console.WriteLine("thats okey");
}
Console.Read();
}