Class: CryptoToolchain::BlackBoxes::EcbOrCbcEncryptor
- Defined in:
- lib/crypto_toolchain/black_boxes/ecb_or_cbc_encryptor.rb
Constant Summary collapse
- ENCRYPTION_ALGORITHMS =
%i(ebc cbc).freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#plaintext ⇒ Object
readonly
Returns the value of attribute plaintext.
Instance Method Summary collapse
- #encrypt(_algo = algorithm) ⇒ Object
-
#initialize(plaintext, algorithm: random_algorithm) ⇒ EcbOrCbcEncryptor
constructor
A new instance of EcbOrCbcEncryptor.
Constructor Details
#initialize(plaintext, algorithm: random_algorithm) ⇒ EcbOrCbcEncryptor
Returns a new instance of EcbOrCbcEncryptor.
7 8 9 10 11 12 |
# File 'lib/crypto_toolchain/black_boxes/ecb_or_cbc_encryptor.rb', line 7 def initialize(plaintext, algorithm: random_algorithm) raise ArgumentError.new("Unsupported algorithm #{algorithm}") unless ENCRYPTION_ALGORITHMS.include? algorithm @plaintext = plaintext @key = String.random_bytes(16) @algorithm = algorithm end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/crypto_toolchain/black_boxes/ecb_or_cbc_encryptor.rb', line 5 def key @key end |
#plaintext ⇒ Object (readonly)
Returns the value of attribute plaintext.
5 6 7 |
# File 'lib/crypto_toolchain/black_boxes/ecb_or_cbc_encryptor.rb', line 5 def plaintext @plaintext end |
Instance Method Details
#encrypt(_algo = algorithm) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/crypto_toolchain/black_boxes/ecb_or_cbc_encryptor.rb', line 14 def encrypt(_algo = algorithm) case _algo when :ecb encrypt_ecb when :cbc encrypt_cbc end end |