Class: Objc_Obfuscator::StringEncryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/objc-obfuscator/stringencryptor.rb

Defined Under Namespace

Classes: EncryptorError

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/objc-obfuscator/stringencryptor.rb', line 8

def key
  @key
end

#last_ivObject (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_saltObject (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.default_options.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