class SlackSmartBot
module Utils
module Encryption
def self.encryption_get_key_iv(config)
if defined?(@encryption_key_built)
key = @encryption_key_built
iv = @encryption_iv_built
else
if config.key?(:encryption) and config.encryption.key?(:key) and config.encryption.key?(:iv)
key = config[:encryption][:key]
iv = config[:encryption][:iv]
else
key = (Socket.gethostname + config.token.reverse)[0..49]
iv = config.token[0..15]
end
key = [key].pack("H*")
key << ("\x00" * (32 - key.length))
iv = [iv].pack("H*")
iv << ("\x00" * (16 - iv.length))
@encryption_key_built = key
@encryption_iv_built = iv
end
return key, iv
end
end
end
end