Class: IGMarkets::PasswordEncryptor
- Inherits:
-
Object
- Object
- IGMarkets::PasswordEncryptor
- Defined in:
- lib/ig_markets/password_encryptor.rb
Overview
Encrypts account passwords in the manner required for authentication with the IG Markets API.
Instance Attribute Summary collapse
-
#public_key ⇒ OpenSSL::PKey::RSA
The public key used by #encrypt, can also be set using #encoded_public_key=.
-
#time_stamp ⇒ String
The time stamp used by #encrypt.
Instance Method Summary collapse
-
#encoded_public_key=(encoded_public_key) ⇒ Object
Takes an encoded public key and calls #public_key= with the decoded key.
-
#encrypt(password) ⇒ String
Encrypts a password using this encryptor’s public key and time stamp, which must have been set prior to calling this method.
-
#initialize(encoded_public_key = nil, time_stamp = nil) ⇒ PasswordEncryptor
constructor
Initializes this password encryptor with the specified encoded public key and timestamp.
Constructor Details
#initialize(encoded_public_key = nil, time_stamp = nil) ⇒ PasswordEncryptor
Initializes this password encryptor with the specified encoded public key and timestamp.
20 21 22 23 |
# File 'lib/ig_markets/password_encryptor.rb', line 20 def initialize(encoded_public_key = nil, time_stamp = nil) self.encoded_public_key = encoded_public_key if encoded_public_key self.time_stamp = time_stamp end |
Instance Attribute Details
#public_key ⇒ OpenSSL::PKey::RSA
The public key used by #encrypt, can also be set using #encoded_public_key=.
9 10 11 |
# File 'lib/ig_markets/password_encryptor.rb', line 9 def public_key @public_key end |
#time_stamp ⇒ String
The time stamp used by #encrypt.
14 15 16 |
# File 'lib/ig_markets/password_encryptor.rb', line 14 def time_stamp @time_stamp end |
Instance Method Details
#encoded_public_key=(encoded_public_key) ⇒ Object
Takes an encoded public key and calls #public_key= with the decoded key.
28 29 30 |
# File 'lib/ig_markets/password_encryptor.rb', line 28 def encoded_public_key=(encoded_public_key) self.public_key = OpenSSL::PKey::RSA.new Base64.strict_decode64 encoded_public_key end |
#encrypt(password) ⇒ String
Encrypts a password using this encryptor’s public key and time stamp, which must have been set prior to calling this method.
38 39 40 41 42 43 44 |
# File 'lib/ig_markets/password_encryptor.rb', line 38 def encrypt(password) encoded_password = Base64.strict_encode64 "#{password}|#{time_stamp}" encrypted_password = public_key.public_encrypt encoded_password Base64.strict_encode64 encrypted_password end |