Class: EllipticCurve::PrivateKey
- Inherits:
-
Object
- Object
- EllipticCurve::PrivateKey
- Defined in:
- lib/privatekey.rb
Instance Attribute Summary collapse
-
#openSslPrivateKey ⇒ Object
readonly
Returns the value of attribute openSslPrivateKey.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(curve = "secp256k1", openSslKey = nil) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
- #publicKey ⇒ Object
- #toDer ⇒ Object
- #toPem ⇒ Object
- #toString ⇒ Object
Constructor Details
#initialize(curve = "secp256k1", openSslKey = nil) ⇒ PrivateKey
Returns a new instance of PrivateKey.
10 11 12 13 14 15 16 17 |
# File 'lib/privatekey.rb', line 10 def initialize(curve="secp256k1", openSslKey=nil) if openSslKey.nil? @openSslPrivateKey = OpenSSL::PKey::EC.new(curve) @openSslPrivateKey.generate_key else @openSslPrivateKey = openSslKey end end |
Instance Attribute Details
#openSslPrivateKey ⇒ Object (readonly)
Returns the value of attribute openSslPrivateKey.
19 20 21 |
# File 'lib/privatekey.rb', line 19 def openSslPrivateKey @openSslPrivateKey end |
Class Method Details
.fromDer(string) ⇒ Object
43 44 45 |
# File 'lib/privatekey.rb', line 43 def self.fromDer(string) return PrivateKey.new(nil, OpenSSL::PKey::EC.new(string)) end |
.fromPem(string) ⇒ Object
39 40 41 |
# File 'lib/privatekey.rb', line 39 def self.fromPem(string) return PrivateKey.new(nil, OpenSSL::PKey::EC.new(string)) end |
.fromString(string) ⇒ Object
47 48 49 |
# File 'lib/privatekey.rb', line 47 def self.fromString(string) return PrivateKey.new(nil, OpenSSL::PKey::EC.new(Base64.decode64(string))) end |
Instance Method Details
#publicKey ⇒ Object
21 22 23 24 25 |
# File 'lib/privatekey.rb', line 21 def publicKey dupKey = OpenSSL::PKey::EC.new(@openSslPrivateKey.to_der()) dupKey.private_key = nil return PublicKey.new(dupKey) end |
#toDer ⇒ Object
31 32 33 |
# File 'lib/privatekey.rb', line 31 def toDer return @openSslPrivateKey.to_der() end |
#toPem ⇒ Object
35 36 37 |
# File 'lib/privatekey.rb', line 35 def toPem return @openSslPrivateKey.to_pem() end |
#toString ⇒ Object
27 28 29 |
# File 'lib/privatekey.rb', line 27 def toString return Base64.encode64(self.toDer()) end |