class Objc_Obfuscator::StringEncryptor
Attributes
key[RW]
last_iv[R]
last_salt[R]
Public Class Methods
new(key)
click to toggle source
# File lib/objc-obfuscator/stringencryptor.rb, line 14 def initialize(key) @key = key end
Public Instance Methods
encrypt(unencrypted_string)
click to toggle source
# 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