2017-11-27 13 views
0

NBitcoin Nuget 패키지를 사용하고 있습니다. 개인 및 출판 키 (주소)를 만들려고합니다. 그리고 나서, 나는 어떤 메시지에 사인을 한 다음이 사인을 pub key로 확인하려고합니다. 그러나 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"); 

이것이 전부입니다. 공개 키를 원하는 위치에 저장하는 것은 안전합니다. 개인 키를 배울 수 없기 때문입니다.