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 #=> trueConstant Summary
- 
    EXPLICIT_CURVE =
    
 # File 'ext/openssl/ossl_pkey_ec.c', line 1723INT2NUM(OPENSSL_EC_EXPLICIT_CURVE) 
- 
    NAMED_CURVE =
    
 # File 'ext/openssl/ossl_pkey_ec.c', line 1721INT2NUM(OPENSSL_EC_NAMED_CURVE) 
Class Method Summary
- 
    
      .builtin_curves  ⇒ Array, comment 
    
    Obtains a list of all predefined curves by the ::OpenSSL. 
- 
    
      .generate(ec_group)  ⇒ EC 
    
    Creates a new ECinstance with a new random private and public key.
- 
    
      .new  
    
    constructor
    Creates a new ECobject from given arguments.
PKey - Inherited
| .new | Because PKey is an abstract class, actually calling this method explicitly will raise a  | 
Instance Attribute Summary
- 
    
      #group  ⇒ group 
    
    rw
    Returns the Group that the key is associated with. 
- 
    
      #group=(group)  
    
    rw
    Sets the Group for the key. 
- 
    
      #private_key  ⇒ OpenSSL::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_key  ⇒ EC 
    
    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(). 
- 
    
      #private?  ⇒ Boolean 
      (also: #private_key?)
    
    readonly
    Returns whether this ECinstance has a private key.
- 
    
      #public?  ⇒ Boolean 
      (also: #public_key?)
    
    readonly
    Returns whether this ECinstance has a public key.
Instance Method Summary
- 
    
      #check_key  ⇒ true 
    
    Raises an exception if the key is invalid. 
- 
    
      #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 
      (also: #to_pem)
    
    Outputs the ECkey in PEM encoding.
- 
    
      #generate_key  ⇒ self 
      (also: #generate_key!)
    
    Generates a new random private and public key. 
- 
    
      #generate_key!  ⇒ self 
    
    Alias for #generate_key. 
- 
    
      #private_key?  ⇒ Boolean 
    
    rw
    Alias for #private?. 
- 
    
      #public_key?  ⇒ Boolean 
    
    rw
    Alias for #public?. 
- 
    
      #to_der  ⇒ String 
    
    See the ::OpenSSL documentation for i2d_ECPrivateKey_bio(). 
- 
    
      #to_pem([cipher, pass_phrase])  ⇒ String 
    
    Alias for #export. 
- 
    
      #to_text  ⇒ String 
    
    See the ::OpenSSL documentation for EC_KEY_print(). 
PKey - Inherited
| #sign | To sign the  | 
| #verify | To verify the  | 
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_curves  ⇒ Array, comment   
    
      .generate(ec_group)  ⇒ EC 
      .generate(string)  ⇒ EC 
    
  
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)
    #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_key ⇒ OpenSSL::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_key  ⇒ EC  (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_key  ⇒ true   
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
  
String 
      #to_pem([cipher, pass_phrase])  ⇒ String 
    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_key  ⇒ self     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_key  ⇒ self 
      #generate_key!  ⇒ self 
    
  
self 
      #generate_key!  ⇒ self 
    Alias for #generate_key.
    
      #private?  ⇒ Boolean  (rw)
      #private_key?  ⇒ Boolean 
    
  
Boolean  (rw)
      #private_key?  ⇒ Boolean 
    Alias for #private?.
    
      #public?  ⇒ Boolean  (rw)
      #public_key?  ⇒ Boolean 
    
  
Boolean  (rw)
      #public_key?  ⇒ Boolean 
    Alias for #public?.
    #to_der  ⇒ String   
See the ::OpenSSL documentation for i2d_ECPrivateKey_bio()
    
      #export([cipher, pass_phrase])  ⇒ String 
      #to_pem([cipher, pass_phrase])  ⇒ String 
    
  
String 
      #to_pem([cipher, pass_phrase])  ⇒ String 
    Alias for #export.
    #to_text  ⇒ String   
See the ::OpenSSL documentation for EC_KEY_print()