# Openssl. question about ec

**URL:** <https://rubytalk.org/t/openssl-question-about-ec/59386>\
**Category:** ruby-talk\
**Created:** [28 July 2010 11:15 UTC](https://rubytalk.org/t/openssl-question-about-ec/59386 "2010-07-28T11:15:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Catz](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Roman\_Catz](https://rubytalk.org/u/Roman_Catz)\
**Post date:** [28 July 2010 11:15 UTC](https://rubytalk.org/t/openssl-question-about-ec/59386/1 "2010-07-28T11:15:05Z")

</div>

Hi all, I have a question about openssl library  
Here it is.

'Security on rails' book has a sample

require 'openssl'  
include OpenSSL

private\_key2 = PKey::RSA.new(File.read("host.key"))  
cert2 = X509::Certificate.new(File.read('host.crt'))

input = "Test string"  
signature2 = private\_key2.sign(OpenSSL::Digest::SHA512.new, input)

is\_verified2 = cert2.public\_key.verify(OpenSSL::Digest::SHA512.new,  
signature2, input)  
puts is\_verified2

All works well until I switched to ec algorithm

Example:  
localhost:openssl roman$ openssl ecparam -name secp521r1 -genkey -  
out ./ca/ca.key  
localhost:openssl roman$ openssl req -new -key ./ca/ca.key -sha512 -  
out ./ca/ca.req

localhost:openssl roman$ openssl ca -days 365 -policy policy\_anything -  
keyfile ./ca/ca.key -in ./ca/ca.req -selfsign -out ./ca/ca.crt -  
outdir ./ca

All files prepared. Let's test the code

private\_key1 = PKey::EC.new(File.read("./ca/ca.key"))  
cert1 = X509::Certificate.new(File.read('./ca/ca.crt'))  
input = "Test string"  
signature = private\_key1.sign(OpenSSL::Digest::SHA1.new, input)

output is:  
undefined method `private?' for #\<OpenSSL::PKey::EC:0x100378740\>

actually OpenSSL::PKey::EC doesn't have method 'private?'  
but OpenSSL::PKey::RSA has.

I tried to add method

def private\_key1.private?  
&nbsp;&nbsp;&nbsp;self.private\_key?  
end

But another error exists

signature1 = private\_key1.sign(OpenSSL::Digest::SHA1.new, input)  
outputs:  
OpenSSL::PKey::PKeyError: wrong public key type

Can anyone explain where is the error here?

TIA Roman
