public void CanVerifySignature() { var tests = new[] { new { Address = "15jZVzLc9cXz5PUFFda5A4Z7kZDYPg2NnL", PrivateKey = "L3TiCqmvPkXJpzCCZJuhy6wQtJZWDkR1AuqFY4Utib5J5XLuvLdZ", Message = "This is an example of a signed message.", Signature = "H6sliOnVrD9r+J8boZAKHZwBIW2zLiD72IfTIF94bfZhBI0JdMu9AM9rrF7P6eH+866YvM4H9xWGVN4jMJZycFU=" }, new { Address = "1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ", PrivateKey = "5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj", Message = "hello world", Signature = "G+dnSEywl3v1ijlWXvpY6zpu+AKNNXJcVmrdE35m0mMlzwFzXDiNg+uZrG9k8mpQL6sjHKrlBoDNSA+yaPW7PEA=" }, new { Address = "1Q1wVsNNiUo68caU7BfyFFQ8fVBqxC2DSc", PrivateKey = null as string, Message = "Localbitcoins.com will change the world", Signature = "IJ/17TjGGUqmEppAliYBUesKHoHzfY4gR4DW0Yg7QzrHUB5FwX1uTJ/H21CF8ncY8HHNB5/lh8kPAOeD5QxV8Xc=" }, new { Address = "1GvPJp7H8UYsYDvE4GFoV4f2gSCNZzGF48", PrivateKey = "5JEeah4w29axvf5Yg9v9PKv86zcCN9qVbizJDMHmiSUxBqDFoUT", Message = "This is an example of a signed message2", Signature = "G8YNwlo+I36Ct+hZKGSBFl3q8Kbx1pxPpwQmwdsG85io76+DUOHXqh/DfBq+Cn2R3C3dI//g3koSjxy7yNxJ9m8=" }, new { Address = "1GvPJp7H8UYsYDvE4GFoV4f2gSCNZzGF48", PrivateKey = "5JEeah4w29axvf5Yg9v9PKv86zcCN9qVbizJDMHmiSUxBqDFoUT", Message = "this is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long messagethis is a very long message", Signature = "HFKBHewleUsotk6fWG0OvWS/E2pP4o5hixdD6ui60in/x4376FBI4DvtJYrljXLNJTG1pBOZG+qRT/7S9WiIBfQ=" }, }; foreach (var test in tests) { if (test.PrivateKey != null) { var secret = Network.Main.CreateBitcoinSecret(test.PrivateKey); var signature = secret.PrivateKey.SignMessage(test.Message); Assert.True(Network.Main.CreateBitcoinAddress(test.Address).VerifyMessage(test.Message, signature)); Assert.True(secret.PubKey.VerifyMessage(test.Message, signature)); } BitcoinAddress address = Network.Main.CreateBitcoinAddress(test.Address); Assert.True(address.VerifyMessage(test.Message, test.Signature)); Assert.True(!address.VerifyMessage("bad message", test.Signature)); } }
private void buttonVerify_Click(object sender, EventArgs e) { try { using (new HourGlass()) { var fromBase58 = Util.Interpret(textBoxBase58.Text); if (fromBase58 is BitcoinSecret) { secret = fromBase58 as BitcoinSecret; address = secret.GetAddress(); } else { address = fromBase58 as BitcoinAddress; } sig = textBoxSig.Text; msg = textBoxMessage.Text; } string valid = address.VerifyMessage(msg, sig).ToString(); MessageBox.Show(this, valid, "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void ProcessRespondBitId(BitIdCredentials credentials, HttpResponse response) { BitcoinAddress testAddress = new BitcoinAddress(credentials.address); if (testAddress.VerifyMessage(credentials.uri, credentials.signature)) { // woooooo try { if (CurrentUser != null) { if ((string)GuidCache.Get(credentials.uri + "-Intent") == "Register") { // the currently logged-on user desires to register this address // so set currentUser bitid CurrentUser.BitIdAddress = credentials.address; // Then go do something else, I guess? Flag somehow to original page // that the op is completed? GuidCache.Set(credentials.uri + "-Intent", "Complete"); } } if (GuidCache.Get(credentials.uri + "-Logon") as string == "Unauth") { Person person = Person.FromBitIdAddress(credentials.address); // TODO: If above throws, show friendly "unknown wallet" message // TODO: Determine last logged-on organization. Right now, log on to Sandbox. GuidCache.Set(credentials.uri + "-LoggedOn", person.Identity.ToString(CultureInfo.InvariantCulture) + ",1,,BitId 2FA"); } } catch (Exception e) { Persistence.Key["BitIdLogin_Debug_Exception"] = e.ToString(); } // TODO: Error codes response.StatusCode = 200; response.SetJson(); response.Write("{\"address\":\"" + credentials.address + "\",\"signature\":\"" + credentials.signature + "\"}"); response.End(); } else { response.StatusCode = 401; // Be a bit more friendly in your return codes } }