Bitcoin Forum
November 13, 2024, 03:32:28 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What is possible to validate on a public key  (Read 1278 times)
varChar (OP)
Member
**
Offline Offline

Activity: 92
Merit: 10


View Profile
September 29, 2014, 06:50:53 PM
 #1

Read here: https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses that it is between 25 and 34 characters. Is this correct? Is there anything more that is possible to check that it is a correct public key?
TimS
Sr. Member
****
Offline Offline

Activity: 250
Merit: 253


View Profile WWW
September 29, 2014, 08:31:31 PM
 #2

No, you can't check if the address represents a valid public key, because you can't reverse the hashing that turned the public key into the address.

You can check if a given string is a valid base58check encoding of some data, see what version byte was attached to the address, and how long the actual data encoded is. But the data itself is an inscrutable 20 bytes.
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 267


View Profile
September 30, 2014, 01:45:17 AM
 #3

Well, a hash is 20 byte long and the public key is 'nearly' 32 byte long. So essentially, there are thousands of public keys for any address. But of course, you can't check whether someone knows the matching private key.

varChar (OP)
Member
**
Offline Offline

Activity: 92
Merit: 10


View Profile
September 30, 2014, 06:06:19 AM
 #4

Ok. Perhaps I discribed it wrong. But not to see if it is a valid public key. More if it is a public key. Thing like that it is >= 25 && <= 34, begins with 1 or 3(?). And things like that.
But perhaps it's enough to see if it is a valid base58check as you said. Didn't know of that. So Perhaps it's what Im searching for. Thanks
ForgottenPassword
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
September 30, 2014, 06:09:00 AM
 #5

If you are using Bitcoin Core you can use the validateaddress API call.

I have private messages disabled. Send me an email instead. My contact details can be found here.

Tip Address: 13Lwo1hK5smoBpFWxmqeKSL52EvN8U7asX
varChar (OP)
Member
**
Offline Offline

Activity: 92
Merit: 10


View Profile
September 30, 2014, 08:19:48 AM
 #6

If you are using Bitcoin Core you can use the validateaddress API call.

No it's a c# project where the user will enter a public key.
ForgottenPassword
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
September 30, 2014, 08:33:49 AM
Last edit: September 30, 2014, 08:58:52 AM by ForgottenPassword
 #7

If you are using Bitcoin Core you can use the validateaddress API call.

No it's a c# project where the user will enter a public key.

Perhaps you are mixed up, a Bitcoin address and a public key are two different things.

A bitcoin address looks like this:
1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN

A public key looks like this:
04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0f a8722476c7709c02559e3aa73aa03918ba2d492eea75abea235

If you want to validate a bitcoin address, you can check the length, check if it begins with a 1 or 3, check if it is valid base58 and check if the checksum is valid. Here is a Ruby script that does all of this which you can use as a reference:

https://gist.github.com/alexandrz/4491729

If you want to check if a public key is valid, you can also check the length and check that it is hex. There is no checksum on ecdsa pubkeys. see post below.

I have private messages disabled. Send me an email instead. My contact details can be found here.

Tip Address: 13Lwo1hK5smoBpFWxmqeKSL52EvN8U7asX
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 267


View Profile
September 30, 2014, 08:54:29 AM
 #8

Ok. Perhaps I discribed it wrong. But not to see if it is a valid public key. More if it is a public key. Thing like that it is >= 25 && <= 34, begins with 1 or 3(?). And things like that.
But perhaps it's enough to see if it is a valid base58check as you said. Didn't know of that. So Perhaps it's what Im searching for. Thanks

You can convert back to Hex. Then verify the checksum and the version byte. The later is what differentiates a bitcoin main address from a testnet address or a altcoin address.

Perhaps you are mixed up, a Bitcoin address and a public key are two different things.

A bitcoin address looks like this:
1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN

A public key looks like this:
04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0f a8722476c7709c02559e3aa73aa03918ba2d492eea75abea235

If you want to check if a public key is valid, you can also check the length and check that it is hex. There is no checksum on ecdsa pubkeys.

There are some checks you can do on a public key.
There are two types of pub keys in bitcoin: compressed or uncompressed. They are 33 and 65 byte long respectively.
If it begins with 04, it's uncompressed. If it's 02 or 03, it is compressed.
So you can check the first byte.
If it's uncompressed, the next 32 + 32 bytes is the X and Y coordinates of a point on the Y^2 = X^3 + 7 curve. You can check that too
Note that it must be done modulo N = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141
If it's compressed, only the X coordinate is given. It must be lower than N

This can be done by your EC crypto library when you decode the pubkey.

varChar (OP)
Member
**
Offline Offline

Activity: 92
Merit: 10


View Profile
September 30, 2014, 01:42:01 PM
 #9

If you are using Bitcoin Core you can use the validateaddress API call.

No it's a c# project where the user will enter a public key.

Perhaps you are mixed up, a Bitcoin address and a public key are two different things.

A bitcoin address looks like this:
1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN

A public key looks like this:
04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0f a8722476c7709c02559e3aa73aa03918ba2d492eea75abea235

If you want to validate a bitcoin address, you can check the length, check if it begins with a 1 or 3, check if it is valid base58 and check if the checksum is valid. Here is a Ruby script that does all of this which you can use as a reference:

https://gist.github.com/alexandrz/4491729

If you want to check if a public key is valid, you can also check the length and check that it is hex. There is no checksum on ecdsa pubkeys. see post below.

Thank you! It's the address I want to check. Actually thought that the address was the public key.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!