Class: Etna::SignService
- Inherits:
-
Object
- Object
- Etna::SignService
- Defined in:
- lib/etna/sign_service.rb
Instance Method Summary collapse
- #generate_private_key(key_size) ⇒ Object
- #hash_password(password) ⇒ Object
- #hmac(message, key) ⇒ Object
-
#initialize(application) ⇒ SignService
constructor
A new instance of SignService.
- #jwt_decode(token) ⇒ Object
- #jwt_token(payload) ⇒ Object
- #private_key ⇒ Object
- #public_key ⇒ Object
- #uid(size = nil) ⇒ Object
Constructor Details
#initialize(application) ⇒ SignService
Returns a new instance of SignService.
7 8 9 |
# File 'lib/etna/sign_service.rb', line 7 def initialize(application) @application = application end |
Instance Method Details
#generate_private_key(key_size) ⇒ Object
55 56 57 |
# File 'lib/etna/sign_service.rb', line 55 def generate_private_key(key_size) OpenSSL::PKey::RSA.generate(key_size) end |
#hash_password(password) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/etna/sign_service.rb', line 11 def hash_password(password) signature( [ password, @application.config(:pass_salt) ], @application.config(:pass_algo) ) end |
#hmac(message, key) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/etna/sign_service.rb', line 18 def hmac(, key) OpenSSL::HMAC.hexdigest( 'SHA256', key, ) end |
#jwt_decode(token) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/etna/sign_service.rb', line 38 def jwt_decode(token) return JWT.decode( token, public_key, true, algorithm: @application.config(:token_algo) ) end |
#jwt_token(payload) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/etna/sign_service.rb', line 26 def jwt_token(payload) return JWT.encode( payload, private_key, @application.config(:token_algo) ) end |
#private_key ⇒ Object
47 48 49 |
# File 'lib/etna/sign_service.rb', line 47 def private_key @private_key ||= OpenSSL::PKey::RSA.new(@application.config(:rsa_private)) end |
#public_key ⇒ Object
51 52 53 |
# File 'lib/etna/sign_service.rb', line 51 def public_key @public_key ||= OpenSSL::PKey::RSA.new(@application.config(:rsa_public)) end |
#uid(size = nil) ⇒ Object
34 35 36 |
# File 'lib/etna/sign_service.rb', line 34 def uid(size=nil) SecureRandom.hex(size) end |