$30 bounty: How to use the RSA PEAR package? How do I use a .key file to sign a str.?

The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

$30 bounty: How to use the RSA PEAR package? How do I use a .key file to sign a str.?

Hi,

My head is completely blocked on this issue. I'm even shaking from desperation of this... Our government has surely made it extremely difficult to understand the law... Anyway, I'm drifting away, so back to the subject.

I have a key pair (.cer/.key - public/private), which was handed to me by the government.

I'm supposed to sign invoices with the private key, and even though they don't provide much detail, I kinda arrived at the conclusion I could use PHP for the work.

First, I need to create an MD5 hash of a string. Then I have to sign it with the public key, and then I need to convert the signature to base64.

The middle step I don't know how to do. It seems that the RSA PEAR package only accepts strings, so how could I convert my .key file so I can use it to sign my invoices?

Warning: openssl_private_encrypt(): key param is not a valid private key

So it would seem openssl_get_privatekey somehow doesn't understand my private key because it's not loading it... The key is not corrupt or anything like that, because I've already used it to sign other stuff, with the program provided by the government. Unfortunately, that stupid program doesn't sign arbitrary data, so I'm off to create my own damn solution.