<p>The difference is that the first function uses uncompressed public keys , and the second function uses compressed public keys. Uncompressed public keys are 65 bytes , and compressed ones are 33 bytes.</p>

<p>For more information on compressed public keys see: <a href="https://bitcoin.stackexchange.com/questions/3059/what-is-a-compressed-bitcoin-key">What is a compressed Bitcoin key?</a></p>

CC BY-SA 3.0
2015-07-13T22:39:06.093Z
2015-07-13T22:39:06.093Z
2017-04-13T12:47:36.647Z
k kurokawa
<p>It seems like depending on the method you get different public keys and addresses when using bitcoin-ruby with the same private key. I am probably doing something wrong, but I am not sure where it is...</p>

<p>I can generate a private key, public key, and address using </p>

<pre><code>def generate_address
  private_key, public_key = Bitcoin::generate_key
  address = Bitcoin::pubkey_to_address(public_key)
  [private_key, public_key, address]
end
</code></pre>

<p>And, as an example, this could generate:</p>

<pre><code>priv_key= "9d524654045c891327a1dc0c329bcd42311b1767b81d7e997486e841ca5a2a87"
publ_key = "04353457464a32ede1b80fd7299f616320b52cc22796cd27d5b41594f418c2ea26dfeec97273f89b2d908a44fce981ff19f2e2de1408538bb0c0528992ce47f3be"
address = "n1693JDDu5ukbtNh2sHXdZSobKnVEpdtjL"
</code></pre>

<p>However, if I then put the private key into another function which generates the key details in a different way, I get a different address! Why is this?</p>

<pre><code>def key_details(prikey)
  #returns prikey, prikey_hash58, pubkey_hash58, pubkey_uncompressed, address as a hash
  my_key = Bitcoin::Key.new(prikey)
  # binding.pry
  { prikey:prikey, 
    prikey_base58:my_key.to_base58, 
    pubkey_58:my_key.pub, 
    pubkey: my_key.pub_uncompressed, 
    address:my_key.addr
  }
end
</code></pre>

<private-key><public-key><ruby>
Does a private key always generate the same public key and address?
Ethan
# Does a private key always generate the same public key and address?

(Asked by: username_0 on 2015-07-13)

It seems like depending on the method you get different public keys and addresses when using bitcoin-ruby with the same private key. I am probably doing something wrong, but I am not sure where it is...

I can generate a private key, public key, and address using

```
def generate_address
  private_key, public_key = Bitcoin::generate_key
  address = Bitcoin::pubkey_to_address(public_key)
  [private_key, public_key, address]
end

```

And, as an example, this could generate:

```
priv_key= "9d524654045c891327a1dc0c329bcd42311b1767b81d7e997486e841ca5a2a87"
publ_key = "04353457464a32ede1b80fd7299f616320b52cc22796cd27d5b41594f418c2ea26dfeec97273f89b2d908a44fce981ff19f2e2de1408538bb0c0528992ce47f3be"
address = "n1693JDDu5ukbtNh2sHXdZSobKnVEpdtjL"

```

However, if I then put the private key into another function which generates the key details in a different way, I get a different address! Why is this?

```
def key_details(prikey)
  #returns prikey, prikey_hash58, pubkey_hash58, pubkey_uncompressed, address as a hash
  my_key = Bitcoin::Key.new(prikey)
  # binding.pry
  { prikey:prikey, 
    prikey_base58:my_key.to_base58, 
    pubkey_58:my_key.pub, 
    pubkey: my_key.pub_uncompressed, 
    address:my_key.addr
  }
end

```

**Tags:** private-key, public-key, ruby


---

## 1 answers

### Answer by username_1 on 2015-07-13. Score: 3

The difference is that the first function uses uncompressed public keys , and the second function uses compressed public keys. Uncompressed public keys are 65 bytes , and compressed ones are 33 bytes.

For more information on compressed public keys see: [What is a compressed Bitcoin key?](https://bitcoin.stackexchange.com/questions/3059/what-is-a-compressed-bitcoin-key)


---

