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 timestamp 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.
Instance Attribute Details
#public_key ⇒ OpenSSL::PKey::RSA
Returns The public key used by #encrypt, can also be set using #encoded_public_key=.
5 6 7 |
# File 'lib/ig_markets/password_encryptor.rb', line 5 def public_key @public_key end |
#time_stamp ⇒ String
Returns The timestamp used by #encrypt.
8 9 10 |
# File 'lib/ig_markets/password_encryptor.rb', line 8 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.
13 14 15 |
# File 'lib/ig_markets/password_encryptor.rb', line 13 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.
23 24 25 26 27 28 29 |
# File 'lib/ig_markets/password_encryptor.rb', line 23 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 |