2017-11-27 9 views
0

NBitcoin Nugetパッケージを使用しています。私はプライベートとパブのキー(アドレス)を作成しようとします。その後、私は何らかのメッセージに署名して、この署名をパブキーで検証しようとします。しかし、NBitcoinは、秘密鍵オブジェクトを持つBitcoinSecretオブジェクトを使って検証します。だから、なぜこのオブジェクトを使ってNBitcoinを検証するのでしょうか?また、アドレス(pubKey)、署名、メッセージを使用して、秘密鍵なしで署名を検証する方法はありますか? おかげ秘密キーなしで確認する方法(NBitcoin)

 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(); 

      } 

答えて

0

公開鍵が一方向関数のいくつかの種類を利用することにより、秘密鍵から導出される公開鍵は、秘密鍵なしでは存在できません。あなたは、秘密鍵なしで公開鍵を使用する場合は、あなたがverifyerが

File.WriteAllBytes("some/public/location/MyPubKey.key", pubKey.ToBytes()); 

へのアクセス権を持っている

var pubKey = privateKey.PubKey; 

店いくつかの場所に公開鍵を行ったように、秘密鍵から生成検証者が秘密鍵を知らずに公開鍵を読み取らせるようにする

var pubKeyForVerification = File.ReadAllBytes("some/public/location/MyPubKey.key"); 

これはすべてです。そこから秘密鍵を学ぶことは事実上不可能なので、どこにでも公開鍵を格納することは安全です。

関連する問題