class Ronin::Support::Crypto::Key::EC

Represents an EC key.

## Examples

### List supported curves

Crypto::Key::EC.supported_curves
# => ["secp224r1", "secp256k1", "secp384r1", "secp521r1", "prime256v1"]

### Generate a random key

ec = Crypto::Key::EC.random("secp224r1")

@see rubydoc.info/stdlib/openssl/OpenSSL/PKey/EC.html

@since 1.0.0

@api public

Public Class Methods

generate(curve='prime256v1') click to toggle source

Generates a new random EC key.

@param [String] curve

The curve to use. See {supported_curves}.

@return [EC]

The newly generated key.
Calls superclass method
# File lib/ronin/support/crypto/key/ec.rb, line 69
def self.generate(curve='prime256v1')
  super(curve)
end
new(*args) click to toggle source

Initializes the EC key.

@param [Array] args

Additional arguments.

@note

Will print a warning message when running on JRuby about
jruby-openssl's EC key bugs:
* https://github.com/jruby/jruby-openssl/issues/256
*https://github.com/jruby/jruby-openssl/issues/257
Calls superclass method
# File lib/ronin/support/crypto/key/ec.rb, line 85
def initialize(*args)
  if RUBY_ENGINE == 'jruby'
    warn "WARNING: jruby-openssl has multiple bugs wrt parsing EC keys"
    warn " * https://github.com/jruby/jruby-openssl/issues/256"
    warn " * https://github.com/jruby/jruby-openssl/issues/257"
  end

  super(*args)
end
supported_curves() click to toggle source

The supported elliptical curves.

@return [Array<String>]

The supported curve names.
# File lib/ronin/support/crypto/key/ec.rb, line 56
def self.supported_curves
  builtin_curves.map { |(name,desc)| name }
end

Public Instance Methods

curve() click to toggle source

The Elliptical Curve name.

@return [String]

@since 1.1.0

# File lib/ronin/support/crypto/key/ec.rb, line 102
def curve
  group.curve_name
end
size() click to toggle source

The size of the EC key in bits.

@return [Integer, nil]

@since 1.1.0

# File lib/ronin/support/crypto/key/ec.rb, line 113
def size
  if (match = to_text.match(/\((\d+) bit\)/))
    match[1].to_i
  end
end