123456789_123456789_123456789_123456789_123456789_

Class: OpenSSL::PKey::EC

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PKey
Instance Chain:
self, PKey
Inherits: OpenSSL::PKey::PKey
Defined in: ext/openssl/ossl_pkey_ec.c

Overview

EC provides access to Elliptic Curve Digital Signature Algorithm (ECDSA) and Elliptic Curve Diffie-Hellman (ECDH).

Key exchange

ec1 = OpenSSL::PKey::EC.generate("prime256v1")
ec2 = OpenSSL::PKey::EC.generate("prime256v1")
# ec1 and ec2 have own private key respectively
shared_key1 = ec1.dh_compute_key(ec2.public_key)
shared_key2 = ec2.dh_compute_key(ec1.public_key)

p shared_key1 == shared_key2 #=> true

Constant Summary

Class Method Summary

PKey - Inherited

.new

Because PKey is an abstract class, actually calling this method explicitly will raise a NotImplementedError.

Instance Attribute Summary

Instance Method Summary

PKey - Inherited

#sign

To sign the String data, digest, an instance of ::OpenSSL::Digest, must be provided.

#verify

To verify the String signature, digest, an instance of ::OpenSSL::Digest, must be provided to re-compute the message digest of the original data, also a String.

Constructor Details

.new .new(ec_key) .new(ec_group) .new("secp112r1") .new(pem_string [, pwd]) .new(der_string)

Creates a new EC object from given arguments.

Class Method Details

.builtin_curvesArray, comment

Obtains a list of all predefined curves by the ::OpenSSL. Curve names are returned as sn.

See the ::OpenSSL documentation for EC_get_builtin_curves().

.generate(ec_group) ⇒ EC .generate(string) ⇒ EC

Creates a new EC instance with a new random private and public key.

Instance Attribute Details

#group ⇒ group (rw)

Returns the EC::Group that the key is associated with. Modifying the returned group does not affect key.

#group=(group) (rw)

Sets the EC::Group for the key. The group structure is internally copied so modification to #group after assigning to a key has no effect on the key.

#private?Boolean (rw) Also known as: #private_key?

Returns whether this EC instance has a private key. The private key (BN) can be retrieved with #private_key.

#private_keyOpenSSL::BN (rw)

See the ::OpenSSL documentation for EC_KEY_get0_private_key()

#private_key=(openssl_bn) (rw)

See the ::OpenSSL documentation for EC_KEY_set_private_key()

#public?Boolean (rw) Also known as: #public_key?

Returns whether this EC instance has a public key. The public key (EC::Point) can be retrieved with #public_key.

#public_keyEC (rw)

See the ::OpenSSL documentation for EC_KEY_get0_public_key()

#public_key=(ec_point) (rw)

See the ::OpenSSL documentation for EC_KEY_set_public_key()

Instance Method Details

#check_keytrue

Raises an exception if the key is invalid.

See the ::OpenSSL documentation for EC_KEY_check_key()

#dh_compute_key(pubkey) ⇒ String

See the ::OpenSSL documentation for ECDH_compute_key()

#dsa_sign_asn1(data) ⇒ String

See the ::OpenSSL documentation for ECDSA_sign()

#dsa_verify_asn1(data, sig) ⇒ Boolean

See the ::OpenSSL documentation for ECDSA_verify()

#export([cipher, pass_phrase]) ⇒ String #to_pem([cipher, pass_phrase]) ⇒ String
Also known as: #to_pem

Outputs the EC key in PEM encoding. If cipher and pass_phrase are given they will be used to encrypt the key. cipher must be an ::OpenSSL::Cipher instance. Note that encryption will only be effective for a private key, public keys will always be encoded in plain text.

#generate_keyself Also known as: #generate_key!

Generates a new random private and public key.

See also the ::OpenSSL documentation for EC_KEY_generate_key()

Example

ec = OpenSSL::PKey::EC.new("prime256v1")
p ec.private_key # => nil
ec.generate_key!
p ec.private_key # => #<OpenSSL::BN XXXXXX>

#generate_keyself #generate_key!self

Alias for #generate_key.

#private?Boolean (rw) #private_key?Boolean

Alias for #private?.

#public?Boolean (rw) #public_key?Boolean

Alias for #public?.

#to_derString

See the ::OpenSSL documentation for i2d_ECPrivateKey_bio()

#export([cipher, pass_phrase]) ⇒ String #to_pem([cipher, pass_phrase]) ⇒ String

Alias for #export.

#to_textString

See the ::OpenSSL documentation for EC_KEY_print()