Class: Acme::Client::Crypto
- Inherits:
-
Object
- Object
- Acme::Client::Crypto
- Defined in:
- lib/acme/client/crypto.rb
Instance Attribute Summary collapse
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
Instance Method Summary collapse
- #digest ⇒ Object
- #generate_signed_jws(header:, payload:) ⇒ Object
-
#initialize(private_key) ⇒ Crypto
constructor
A new instance of Crypto.
- #thumbprint ⇒ Object
- #urlsafe_base64(data) ⇒ Object
Constructor Details
#initialize(private_key) ⇒ Crypto
Returns a new instance of Crypto.
4 5 6 |
# File 'lib/acme/client/crypto.rb', line 4 def initialize(private_key) @private_key = private_key end |
Instance Attribute Details
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
2 3 4 |
# File 'lib/acme/client/crypto.rb', line 2 def private_key @private_key end |
Instance Method Details
#digest ⇒ Object
29 30 31 |
# File 'lib/acme/client/crypto.rb', line 29 def digest OpenSSL::Digest::SHA256.new end |
#generate_signed_jws(header:, payload:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/acme/client/crypto.rb', line 8 def generate_signed_jws(header:, payload:) header = { typ: 'JWT', alg: jws_alg, jwk: jwk }.merge(header) encoded_header = urlsafe_base64(header.to_json) encoded_payload = urlsafe_base64(payload.to_json) signature_data = "#{encoded_header}.#{encoded_payload}" signature = private_key.sign digest, signature_data encoded_signature = urlsafe_base64(signature) { protected: encoded_header, payload: encoded_payload, signature: encoded_signature }.to_json end |
#thumbprint ⇒ Object
25 26 27 |
# File 'lib/acme/client/crypto.rb', line 25 def thumbprint urlsafe_base64 digest.digest(jwk.to_json) end |
#urlsafe_base64(data) ⇒ Object
33 34 35 |
# File 'lib/acme/client/crypto.rb', line 33 def urlsafe_base64(data) Base64.urlsafe_encode64(data).sub(/[\s=]*\z/, '') end |