ruby_ecdsa
ruby_ecdsa copied to clipboard
How to read from PEM file to sign ECDSA
I have private key in pem format. I want to sign with following code.
signature = ECDSA.sign($group, $private_key, digest, temp_key)
I want to know is how to read from pem file.
This library treats private keys as normal Ruby integers, so if you can figure out how to extract the actual integer value of your private key then you would be able to use it with this library. I don't know how to do that at the moment, but there is probably a way to do it using Ruby's OpenSSL bindings.
It's quite easy (granted, all the lifting is provided by OpenSSL 😄 )
pem_private_key = File.read(private_key_path)
ec_private_key = OpenSSL::PKey::EC.new(pem_private_key)
int_private_key = ec_private_key.private_key.to_i
The int_private_key can then be plugged into ECDSA::sign