Module: ICAPrb::Filter::Steganography::Cryptography
- Defined in:
- lib/icaprb/filter/steganography.rb
Overview
contains the code to encrypt the watermarks
Constant Summary collapse
- Cipher_To_Use =
Cipher to use
'CAMELLIA-256-CBC'
Class Method Summary collapse
-
.decrypt(data, key) ⇒ Object
- decrypt data using the the algorithm given in Cipher_To_Use using OpenSSL parameters: data
- data to decrypt key
-
the key to use when decrypting data - when the default cipher is used, this must be 32 bytes.
-
.encrypt(data, key) ⇒ Object
- encrypt data using the the algorithm given in Cipher_To_Use using OpenSSL parameters: data
- data to encrypt key
-
the key to use when encrypting data - when the default cipher is used, this must be 32 bytes.
Class Method Details
.decrypt(data, key) ⇒ Object
decrypt data using the the algorithm given in Cipher_To_Use using OpenSSL parameters:
- data
-
data to decrypt
- key
-
the key to use when decrypting data - when the default cipher is used, this must be 32 bytes
returns the decrypted string raises an error if the decryption is not successful
40 41 42 43 44 45 46 47 48 |
# File 'lib/icaprb/filter/steganography.rb', line 40 def decrypt(data, key) cipher = OpenSSL::Cipher.new(Cipher_To_Use) cipher.decrypt iv = data[0..15] encrypted_data = data[16...(data.length)] cipher.iv = iv cipher.key = key cipher.update(encrypted_data) + cipher.final end |
.encrypt(data, key) ⇒ Object
encrypt data using the the algorithm given in Cipher_To_Use using OpenSSL parameters:
- data
-
data to encrypt
- key
-
the key to use when encrypting data - when the default cipher is used, this must be 32 bytes
returns the cipher string
24 25 26 27 28 29 30 31 |
# File 'lib/icaprb/filter/steganography.rb', line 24 def encrypt(data, key) cipher = OpenSSL::Cipher.new(Cipher_To_Use) cipher.encrypt iv = cipher.random_iv cipher.key = key encrypted_data = cipher.update(data) + cipher.final iv + encrypted_data end |