Class: Uberpass::Encrypt
- Inherits:
-
Object
- Object
- Uberpass::Encrypt
- Defined in:
- lib/uberpass/encrypt.rb
Instance Attribute Summary collapse
-
#encrypted_data ⇒ Object
readonly
Returns the value of attribute encrypted_data.
-
#encrypted_iv ⇒ Object
readonly
Returns the value of attribute encrypted_iv.
-
#encrypted_key ⇒ Object
readonly
Returns the value of attribute encrypted_key.
Instance Method Summary collapse
-
#initialize(public_key, decrypted_data, pass_phrase = nil) ⇒ Encrypt
constructor
A new instance of Encrypt.
Constructor Details
#initialize(public_key, decrypted_data, pass_phrase = nil) ⇒ Encrypt
Returns a new instance of Encrypt.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/uberpass/encrypt.rb', line 7 def initialize(public_key, decrypted_data, pass_phrase = nil) key = OpenSSL::PKey::RSA.new(public_key, pass_phrase) cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc') cipher.encrypt cipher.key = random_key = cipher.random_key cipher.iv = random_iv = cipher.random_iv @encrypted_data = cipher.update(decrypted_data) @encrypted_data << cipher.final @encrypted_key = key.public_encrypt(random_key) @encrypted_iv = key.public_encrypt(random_iv) end |
Instance Attribute Details
#encrypted_data ⇒ Object (readonly)
Returns the value of attribute encrypted_data.
5 6 7 |
# File 'lib/uberpass/encrypt.rb', line 5 def encrypted_data @encrypted_data end |
#encrypted_iv ⇒ Object (readonly)
Returns the value of attribute encrypted_iv.
5 6 7 |
# File 'lib/uberpass/encrypt.rb', line 5 def encrypted_iv @encrypted_iv end |
#encrypted_key ⇒ Object (readonly)
Returns the value of attribute encrypted_key.
5 6 7 |
# File 'lib/uberpass/encrypt.rb', line 5 def encrypted_key @encrypted_key end |