Module: Rex::Crypto

Defined in:
lib/rex/crypto.rb,
lib/rex/crypto/rc4.rb,
lib/rex/crypto/aes256.rb,
lib/rex/crypto/chacha20.rb,
lib/rex/crypto/key_wrap/nist_sp_800_38f.rb

Defined Under Namespace

Modules: Aes256, KeyDerivation, KeyWrap, Rc4 Classes: Chacha20

Class Method Summary collapse

Class Method Details

.bytes_to_int(bytes) ⇒ Integer

Returns an integer represented as a byte array. Useful for certain key-related operations.

Parameters:

  • bytes (String)

    The bytes to convert

Returns:

  • (Integer)

    The converted value.



35
36
37
# File 'lib/rex/crypto.rb', line 35

def self.bytes_to_int(bytes)
  bytes.each_byte.reduce(0) { |acc, byte| (acc << 8) | byte }
end

.decrypt_aes256(iv, key, value) ⇒ String

Deprecated.

Access via Rex::Crypto::Aes256

Returns a decrypted string using AES256-CBC.

Parameters:

  • iv (String)

    Initialization vector.

  • key (String)

    Secret key.

Returns:

  • (String)

    The decrypted string.



18
19
20
# File 'lib/rex/crypto.rb', line 18

def self.decrypt_aes256(iv, key, value)
  Aes256.decrypt_aes256(iv, key, value)
end

.encrypt_aes256(iv, key, value) ⇒ String

Deprecated.

Access via Rex::Crypto::Aes256

Returns an encrypted string using AES256-CBC.

Parameters:

  • iv (String)

    Initialization vector.

  • key (String)

    Secret key.

Returns:

  • (String)

    The encrypted string.



8
9
10
# File 'lib/rex/crypto.rb', line 8

def self.encrypt_aes256(iv, key, value)
  Aes256.encrypt_aes256(iv, key, value)
end

.int_to_bytes(num) ⇒ Integer

Returns a byte array represented as a big-endian integer. Useful for certain key-related operations.

Parameters:

  • bytes (String)

    The bytes to convert

Returns:

  • (Integer)

    The converted value.



43
44
45
46
47
48
49
50
51
52
# File 'lib/rex/crypto.rb', line 43

def self.int_to_bytes(num)
  bytes = []

  while num > 0
    bytes.unshift(num & 0xff)
    num >>= 8
  end

  bytes.pack("C*")
end

.rc4(key, value) ⇒ Object

Deprecated.

Access via Rex::Crypto::Rc4

Returns a decrypted or encrypted RC4 string.

Parameters:

  • key (String)

    Secret key.

  • (String)


27
28
29
# File 'lib/rex/crypto.rb', line 27

def self.rc4(key, value)
  Rc4.rc4(key, value)
end