Class: Epics::Key
- Inherits:
-
Object
- Object
- Epics::Key
- Defined in:
- lib/epics/key.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #digester ⇒ Object
- #e ⇒ Object
-
#initialize(encoded_key, passphrase = nil) ⇒ Key
constructor
A new instance of Key.
- #n ⇒ Object
-
#public_digest ⇒ Object
concat the exponent and modulus (hex representation) with a single whitespace remove leading zeros from both calculate digest (SHA256) encode as Base64.
- #sign(msg) ⇒ Object
Constructor Details
#initialize(encoded_key, passphrase = nil) ⇒ Key
Returns a new instance of Key.
4 5 6 7 8 9 10 |
# File 'lib/epics/key.rb', line 4 def initialize(encoded_key, passphrase = nil) if encoded_key.kind_of?(OpenSSL::PKey::RSA) self.key = encoded_key else self.key = OpenSSL::PKey::RSA.new(encoded_key) end end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
2 3 4 |
# File 'lib/epics/key.rb', line 2 def key @key end |
Instance Method Details
#digester ⇒ Object
43 44 45 |
# File 'lib/epics/key.rb', line 43 def digester @digester ||= OpenSSL::Digest::SHA256.new end |
#e ⇒ Object
28 29 30 |
# File 'lib/epics/key.rb', line 28 def e self.key.e.to_s(16) end |
#n ⇒ Object
24 25 26 |
# File 'lib/epics/key.rb', line 24 def n self.key.n.to_s(16) end |
#public_digest ⇒ Object
concat the exponent and modulus (hex representation) with a single whitespace remove leading zeros from both calculate digest (SHA256) encode as Base64
18 19 20 21 22 |
# File 'lib/epics/key.rb', line 18 def public_digest c = [ e.gsub(/^0*/,''), n.gsub(/^0*/,'') ].map(&:downcase).join(" ") Base64.encode64(digester.digest(c)).strip end |
#sign(msg) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/epics/key.rb', line 32 def sign(msg) Base64.encode64( key.sign_pss( 'SHA256', msg, salt_length: :digest, mgf1_hash: 'SHA256', ), ).gsub("\n", '') end |