Module: AESCrypt
- Defined in:
- lib/AES.rb
Class Method Summary collapse
- .b64enc(data) ⇒ Object
- .decrypt(password, iv, secretdata) ⇒ Object
- .encrypt(password, iv, cleardata) ⇒ Object
Class Method Details
.b64enc(data) ⇒ Object
26 27 28 |
# File 'lib/AES.rb', line 26 def AESCrypt.b64enc(data) Base64.encode64(data).gsub(/\n/, '') end |
.decrypt(password, iv, secretdata) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/AES.rb', line 17 def AESCrypt.decrypt(password, iv, secretdata) secretdata = Base64::decode64(secretdata) decipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc') decipher.decrypt decipher.key = password decipher.iv = iv if iv != nil decipher.update(secretdata) + decipher.final end |
.encrypt(password, iv, cleardata) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/AES.rb', line 6 def AESCrypt.encrypt(password, iv, cleardata) cipher = OpenSSL::Cipher.new('AES-256-CBC') cipher.encrypt # set cipher to be encryption mode cipher.key = password cipher.iv = iv encrypted = '' encrypted << cipher.update(cleardata) encrypted << cipher.final AESCrypt.b64enc(encrypted) end |