Module: UU::OS::Security::Encryption
- Included in:
- Session
- Defined in:
- uu_os_framework-0.29.16/lib/uu/os/security/encryption.rb
Overview
Provides data encryption and decryption.
Constant Summary
Instance Method Summary (collapse)
-
- (String) decrypt(data, password = nil)
Decrypts the given data.
-
- (String) encrypt(data, password = nil)
Encrypts the given data.
Instance Method Details
- (String) decrypt(data, password = nil)
Decrypts the given data.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'uu_os_framework-0.29.16/lib/uu/os/security/encryption.rb', line 98 def decrypt(data, password = nil) data = Base64.decode64(data) salt = data[8..15] data = data[16..-1] cipher = OpenSSL::Cipher.new(ALGORITHM) cipher.decrypt begin key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(password.nil? ? SECRET : password, salt, 1000, 128) cipher.key = key cipher.iv = key cipher.update(data) + cipher.final rescue cipher.reset cipher.pkcs5_keyivgen(SECRET, salt , 1) cipher.update(data) + cipher.final end end |
- (String) encrypt(data, password = nil)
Encrypts the given data.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'uu_os_framework-0.29.16/lib/uu/os/security/encryption.rb', line 79 def encrypt(data, password = nil) salt = '' 8.times {salt << rand(255).chr} cipher = OpenSSL::Cipher.new(ALGORITHM) cipher.encrypt key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(password.nil? ? SECRET : password, salt, 1000, 128) cipher.key = key cipher.iv = key tmp = cipher.update(data) + cipher.final Base64.strict_encode64("Salted__#{salt}#{tmp}") end |