user131230: I generate the private and the public keys in Shell like that:
openssl ecparam -name secp256k1 -rand /dev/random -genkey -noout -out private-key.pem
openssl ec -in private-key.pem -outform DER | tail -c +8 | head -c 32 | xxd -p -c 32 > bitcoin_private_key.pem
openssl ec -in private-key.pem -pubout -outform DER | tail -c 65 | xxd -p -c 65 > bitcoin_public_key.pem

Then I can take the public key X with:
head -c 66 bitcoin_public_key.pem | tail -c 64

And the last byte of Y with:
tail -c 3 bitcoin_public_key.pem

The compressed public key must be 0x02 + X for an even last byte of Y and 0x03 + X for an odd one.
How to check if the last Y's byte is odd or even?

user26628: Instead of compressing 'by hand' you can have OpenSSL do it:
openssl ec -in privatekey.pem -pubout -conv_form compressed -outform der | tail -c 33 | xxd -p -c 33 >compressedpub.hex

And .pem is usually used to mean PEM format, while the files you are creating are totally not at all or in any way PEM format, so that's very misleading and confusing. I used .hex for my example, but there are other reasonable possibilities.

131230: <p>I generate the private and the public keys in Shell like that:</p>
<pre><code>openssl ecparam -name secp256k1 -rand /dev/random -genkey -noout -out private-key.pem
openssl ec -in private-key.pem -outform DER | tail -c +8 | head -c 32 | xxd -p -c 32 &gt; bitcoin_private_key.pem
openssl ec -in private-key.pem -pubout -outform DER | tail -c 65 | xxd -p -c 65 &gt; bitcoin_public_key.pem
</code></pre>
<p>Then I can take the public key X with:</p>
<pre><code>head -c 66 bitcoin_public_key.pem | tail -c 64
</code></pre>
<p>And the last byte of Y with:</p>
<pre><code>tail -c 3 bitcoin_public_key.pem
</code></pre>
<p>The compressed public key must be <code>0x02 + X</code> for an even last byte of <code>Y</code> and <code>0x03 + X</code> for an odd one.</p>
<p>How to check if the last Y's byte is odd or even?</p>
 26628: <p>Instead of compressing 'by hand' you can have OpenSSL do it:</p>
<pre><code>openssl ec -in privatekey.pem -pubout -conv_form compressed -outform der | tail -c 33 | xxd -p -c 33 &gt;compressedpub.hex
</code></pre>
<p>And .pem is <em>usually</em> used to mean PEM format, while the files you are creating are totally not at all or in any way PEM format, so that's very misleading and confusing. I used .hex for my example, but there are other reasonable possibilities.</p>
