OpenSSL::PKey::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
Constants
No documentation available
No documentation available
Class Methods

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().

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

Creates a new EC object from given arguments.

Instance Methods

Raises an exception if the key is invalid.

See the OpenSSL documentation for EC_KEY_check_key()

See the OpenSSL documentation for ECDH_compute_key()

See the OpenSSL documentation for ECDSA_sign()

See the OpenSSL documentation for ECDSA_verify()

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.

An alias for 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>

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

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.

No documentation available

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

See the OpenSSL documentation for EC_KEY_get0_private_key()

See the OpenSSL documentation for EC_KEY_set_private_key()

An alias for private?

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

See the OpenSSL documentation for EC_KEY_get0_public_key()

See the OpenSSL documentation for EC_KEY_set_public_key()

An alias for public?

See the OpenSSL documentation for i2d_ECPrivateKey_bio()

See the OpenSSL documentation for EC_KEY_print()