Class: Objc_Obfuscator::StringEncryptor
- Inherits:
-
Object
- Object
- Objc_Obfuscator::StringEncryptor
- Defined in:
- lib/objc-obfuscator/stringencryptor.rb
Defined Under Namespace
Classes: EncryptorError
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#last_iv ⇒ Object
readonly
Returns the value of attribute last_iv.
-
#last_salt ⇒ Object
readonly
Returns the value of attribute last_salt.
Instance Method Summary collapse
- #encrypt(unencrypted_string) ⇒ Object
-
#initialize(key) ⇒ StringEncryptor
constructor
A new instance of StringEncryptor.
Constructor Details
#initialize(key) ⇒ StringEncryptor
Returns a new instance of StringEncryptor.
14 15 16 |
# File 'lib/objc-obfuscator/stringencryptor.rb', line 14 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/objc-obfuscator/stringencryptor.rb', line 8 def key @key end |
#last_iv ⇒ Object (readonly)
Returns the value of attribute last_iv.
6 7 8 |
# File 'lib/objc-obfuscator/stringencryptor.rb', line 6 def last_iv @last_iv end |
#last_salt ⇒ Object (readonly)
Returns the value of attribute last_salt.
7 8 9 |
# File 'lib/objc-obfuscator/stringencryptor.rb', line 7 def last_salt @last_salt end |
Instance Method Details
#encrypt(unencrypted_string) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/objc-obfuscator/stringencryptor.rb', line 18 def encrypt(unencrypted_string) raise EncryptorError::Error "FATAL: Can't encrypt with an empty key" if key.empty? return '' if unencrypted_string.empty? salt = Time.now.to_i.to_s iv = OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv Encryptor..merge!(:key => key , :iv => iv, :salt => salt) encrypted_string = Base64.strict_encode64 unencrypted_string.encrypt @last_iv = Base64.strict_encode64 iv @last_salt = Base64.strict_encode64 salt "#{encrypted_string}-#{last_iv}-#{last_salt}" end |