CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/crypto/aes256.rb
Views: 11780
1
# -*- coding: binary -*-
2
3
module Rex
4
module Crypto
5
module Aes256
6
# Returns an encrypted string using AES256-CBC.
7
#
8
# @param iv [String] Initialization vector.
9
# @param key [String] Secret key.
10
# @return [String] The encrypted string.
11
def self.encrypt_aes256(iv, key, value)
12
aes = OpenSSL::Cipher.new('aes-256-cbc')
13
aes.encrypt
14
aes.iv = iv
15
aes.key = key
16
aes.update(value) + aes.final
17
end
18
19
# Returns a decrypted string using AES256-CBC.
20
#
21
# @param iv [String] Initialization vector.
22
# @param key [String] Secret key.
23
# @return [String] The decrypted string.
24
def self.decrypt_aes256(iv, key, value)
25
aes = OpenSSL::Cipher.new('aes-256-cbc')
26
aes.decrypt
27
aes.iv = iv
28
aes.key = key
29
aes.update(value) + aes.final
30
end
31
32
end
33
end
34
end
35
36