14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/agent/util/am_util.rb', line 14
def encrypt text, key
if (text == nil || key == nil)
return nil
end
cipher_text = nil
begin
key = key.length > 16 ? key[(key.length-16)..-1] : key
cipher = OpenSSL::Cipher.new('AES-128-CBC').encrypt
cipher.key = key
cipher.iv = ManageEngine::APMObjectHolder.instance.constants.en_alphabets + ManageEngine::APMObjectHolder.instance.constants.en_numerals
cipher_text = Base64.encode64(cipher.update(text) + cipher.final)
rescue Exception=>e
cipher_text = nil
end
return cipher_text
end
|