# Openssl. question about ec

**URL:** <https://www.ruby-forum.com/t/openssl-question-about-ec/192335>\
**Category:** Ruby\
**Created:** [July 28, 2010, 1:15pm UTC](https://www.ruby-forum.com/t/openssl-question-about-ec/192335 "2010-07-28T13:15:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bbce88/32.png) [@fell](https://www.ruby-forum.com/u/fell)\
**Post date:** [July 28, 2010, 1:15pm UTC](https://www.ruby-forum.com/t/openssl-question-about-ec/192335/1 "2010-07-28T13:15:42Z")

</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?  
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
