module Ronin::Support::Crypto::Mixin

Provides helper methods for cryptographic functions.

@api public

@since 1.0.0

Public Instance Methods

aes128_cipher(**kwargs)
aes128_decrypt(data,**kwargs)
aes128_encrypt(data,**kwargs)
aes256_cipher(**kwargs)
aes256_decrypt(data,**kwargs)
aes256_encrypt(data,**kwargs)
aes_cipher(**kwargs)
Alias for: crypto_aes_cipher
aes_decrypt(data,**kwargs)
Alias for: crypto_aes_decrypt
aes_encrypt(data,**kwargs)
Alias for: crypto_aes_encrypt
cipher(name,**kwargs)
Alias for: crypto_cipher
crypto_aes128_cipher(**kwargs) click to toggle source

Creates a new AES-128 cipher.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher::AES128#initialize}.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] :mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:md5)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [Cipher::AES]

The new AES cipher.

@example

Crypto.aes128_cipher(direction: :encrypt, password: 's3cr3t')
# => #<Ronin::Support::Crypto::Cipher::AES128:0x00007f8bde789648 @key_size=128, @mode=:cbc>

@see Crypto.aes128_cipher

# File lib/ronin/support/crypto/mixin.rb, line 341
def crypto_aes128_cipher(**kwargs)
  Crypto.aes128_cipher(**kwargs)
end
Also aliased as: aes128_cipher
crypto_aes128_decrypt(data,**kwargs) click to toggle source

Decrypts data using AES-128.

@param [#to_s] data

The data to encrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher.aes128_cipher}.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:md5)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.aes128_decrypt

# File lib/ronin/support/crypto/mixin.rb, line 423
def crypto_aes128_decrypt(data,**kwargs)
  Crypto.aes128_decrypt(data,**kwargs)
end
Also aliased as: aes128_decrypt
crypto_aes128_encrypt(data,**kwargs) click to toggle source

Encrypts data using AES-128.

@param [#to_s] data

The data to encrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher.aes128_cipher}.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:md5)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.aes128_encrypt

# File lib/ronin/support/crypto/mixin.rb, line 382
def crypto_aes128_encrypt(data,**kwargs)
  Crypto.aes128_encrypt(data,**kwargs)
end
Also aliased as: aes128_encrypt
crypto_aes256_cipher(**kwargs) click to toggle source

Creates a new AES-256 cipher.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher::AES256#initialize}.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] :mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:sha256)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [Cipher::AES]

The new AES cipher.

@example

Crypto.aes256(direction: :encrypt, password: 's3cr3t')
# => #<Ronin::Support::Crypto::Cipher::AES256:0x00007f8bde789648 @key_size=256, @mode=:cbc>

@see Crypto.aes256_cipher

# File lib/ronin/support/crypto/mixin.rb, line 462
def crypto_aes256_cipher(**kwargs)
  Crypto.aes256_cipher(**kwargs)
end
Also aliased as: aes256_cipher
crypto_aes256_decrypt(data,**kwargs) click to toggle source

Decrypts data using AES-256.

@param [#to_s] data

The data to encrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher.aes256_cipher}.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:sh256)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.aes256_decrypt

# File lib/ronin/support/crypto/mixin.rb, line 544
def crypto_aes256_decrypt(data,**kwargs)
  Crypto.aes256_decrypt(data,**kwargs)
end
Also aliased as: aes256_decrypt
crypto_aes256_encrypt(data,**kwargs) click to toggle source

Encrypts data using AES-256.

@param [#to_s] data

The data to encrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher.aes256_cipher}.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:sha256)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.aes256_encrypt

# File lib/ronin/support/crypto/mixin.rb, line 503
def crypto_aes256_encrypt(data,**kwargs)
  Crypto.aes256_encrypt(data,**kwargs)
end
Also aliased as: aes256_encrypt
crypto_aes_cipher(**kwargs) click to toggle source

Creates a new AES cipher.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher::AES#initialize}.

@option kwargs [Integer] :key_size

The desired key size in bits.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] :mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:sha256)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [Cipher::AES]

The new AES cipher.

@example

crypto_aes_cipher(direction: :encrypt, password: 's3cr3t')
# => #<Ronin::Support::Crypto::Cipher::AES:0x00007f2b84dfa6b8 @key_size=256, @mode=:cbc>

@see Crypto.aes_cipher

# File lib/ronin/support/crypto/mixin.rb, line 214
def crypto_aes_cipher(**kwargs)
  Crypto.aes_cipher(**kwargs)
end
Also aliased as: aes_cipher
crypto_aes_decrypt(data,**kwargs) click to toggle source

Decrypts data using AES.

@param [#to_s] data

The data to encrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher.aes_cipher}.

@option kwargs [Integer] :key_size

The desired key size in bits.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:sha256)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.aes_decrypt

# File lib/ronin/support/crypto/mixin.rb, line 302
def crypto_aes_decrypt(data,**kwargs)
  Crypto.aes_decrypt(data,**kwargs)
end
Also aliased as: aes_decrypt
crypto_aes_encrypt(data,**kwargs) click to toggle source

Encrypts data using AES.

@param [#to_s] data

The data to encrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher.aes_cipher}.

@option kwargs [Integer] :key_size

The desired key size in bits.

@option kwargs [:cbc, :cfb, :ofb, :ctr, Symbol] mode (:cbc)

The desired AES cipher mode.

@option kwargs [Symbol] :hash (:sha256)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.aes_encrypt

# File lib/ronin/support/crypto/mixin.rb, line 258
def crypto_aes_encrypt(data,**kwargs)
  Crypto.aes_encrypt(data,**kwargs)
end
Also aliased as: aes_encrypt
crypto_cipher(name,**kwargs) click to toggle source

Creates a cipher.

@param [String] name

The cipher name.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Cipher#initialize}.

@option kwargs [:encrypt, :decrypt] :direction

Specifies whether to encrypt or decrypt data.

@option kwargs [Symbol] :hash (:sha256)

The algorithm to hash the `:password`.

@option kwargs [String] :key

The secret key to use.

@option kwargs [String] :password

The password for the cipher.

@option kwargs [String] :iv

The optional Initial Vector (IV).

@option kwargs [Integer] :padding

Sets the padding for the cipher.

@return [OpenSSL::Cipher]

The newly created cipher.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@example

crypto_cipher('aes-128-cbc', mode: :encrypt, key 'secret'.md5)
# => #<OpenSSL::Cipher:0x0000000170d108>

@see Crypto.cipher

# File lib/ronin/support/crypto/mixin.rb, line 120
def crypto_cipher(name,**kwargs)
  Crypto.cipher(name,**kwargs)
end
Also aliased as: cipher
crypto_decrypt(data, cipher: ,**kwargs) click to toggle source

Decrypts data using the cipher.

@param [#to_s] data

The data to decrypt.

@param [String] cipher

The cipher name (ex: `"aes-256-cbc"`).

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {cipher}.

@return [String]

The decrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.decrypt

# File lib/ronin/support/crypto/mixin.rb, line 172
def crypto_decrypt(data, cipher: ,**kwargs)
  Crypto.decrypt(data, cipher: cipher, **kwargs)
end
Also aliased as: decrypt
crypto_digest(name) click to toggle source

Looks up a digest.

@param [String, Symbol] name

The name of the digest.

@return [OpenSSL::Digest]

The OpenSSL Digest class.

@example

crypto_digest(:ripemd160)
# => OpenSSL::Digest::RIPEMD160

@see Crypto.digest

# File lib/ronin/support/crypto/mixin.rb, line 47
def crypto_digest(name)
  Crypto.digest(name)
end
Also aliased as: digest
crypto_encrypt(data, cipher: ,**kwargs) click to toggle source

Encrypts data using the cipher.

@param [#to_s] data

The data to encrypt.

@param [String] cipher

The cipher name (ex: `"aes-256-cbc"`).

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {cipher}.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the the `key:` or `password:` keyword argument must be given.

@see Crypto.encrypt

# File lib/ronin/support/crypto/mixin.rb, line 146
def crypto_encrypt(data, cipher: ,**kwargs)
  Crypto.encrypt(data, cipher: cipher, **kwargs)
end
Also aliased as: encrypt
crypto_hmac(data=nil, key: , digest: :sha1) click to toggle source

Creates a new HMAC.

@param [String, nil] data

The optional data to sign.

@param [String] key

The secret key for the HMAC.

@param [Symbol] digest

The digest algorithm for the HMAC.

@return [String]

The hex-encoded HMAC for the String.

@see rubydoc.info/stdlib/openssl/OpenSSL/HMAC

@example

crypto_hmac('secret')

@see Crypto.hmac

# File lib/ronin/support/crypto/mixin.rb, line 75
def crypto_hmac(data=nil, key: , digest: :sha1)
  Crypto.hmac(data, key: key, digest: digest)
end
Also aliased as: hmac
crypto_rsa_decrypt(data,**kwargs) click to toggle source

Decrypts the given data using the given RSA key.

@param [String] data

The data to decrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Crypto.rsa_decrypt}.

@option kwargs [String, nil] :key

The PEM or DER encoded RSA key string.

@option kwargs [String, nil] :key_file

The path to the PEM or DER encoded RSA key file.

@option kwargs [String, nil] :key_password

The optional password to decrypt the encrypted RSA key.

@option kwargs [:pkcs1_oaep, :pkcs1, :sslv23,

              nil, false] :padding (:pkcs1)
Optional padding mode. `nil` and `false` will disable padding.

@return [String]

The decrypted data.

@raise [ArgumentError]

Either the `key:` or `key_file:` keyword argument must be given.
# File lib/ronin/support/crypto/mixin.rb, line 612
def crypto_rsa_decrypt(data,**kwargs)
  Crypto.rsa_decrypt(data,**kwargs)
end
Also aliased as: rsa_decrypt
crypto_rsa_encrypt(data,**kwargs) click to toggle source

Encrypts the given data using the given RSA key.

@param [String] data

The data to encrypt.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments for {Crypto.rsa_encrypt}.

@option kwargs [String, nil] :key

The PEM or DER encoded RSA key string.

@option kwargs [String, nil] :key_file

The path to the PEM or DER encoded RSA key file.

@option kwargs [String, nil] :key_password

The optional password to decrypt the encrypted RSA key.

@option kwargs [:pkcs1_oaep, :pkcs1, :sslv23,

              nil, false] :padding (:pkcs1)
Optional padding mode. `nil` and `false` will disable padding.

@return [String]

The encrypted data.

@raise [ArgumentError]

Either the `key:` or `key_file:` keyword argument must be given.
# File lib/ronin/support/crypto/mixin.rb, line 578
def crypto_rsa_encrypt(data,**kwargs)
  Crypto.rsa_encrypt(data,**kwargs)
end
Also aliased as: rsa_encrypt
decrypt(data, cipher: ,**kwargs)
Alias for: crypto_decrypt
digest(name)
Alias for: crypto_digest
encrypt(data, cipher: ,**kwargs)
Alias for: crypto_encrypt
hmac(data=nil, key: , digest: :sha1)
Alias for: crypto_hmac
rsa_decrypt(data,**kwargs)
Alias for: crypto_rsa_decrypt
rsa_encrypt(data,**kwargs)
Alias for: crypto_rsa_encrypt