Class: BlockCipherKit::AES256CFBCIVScheme
- Inherits:
-
BaseScheme
- Object
- BaseScheme
- BlockCipherKit::AES256CFBCIVScheme
- Defined in:
- lib/block_cipher_kit/aes_256_cfb_civ_scheme.rb
Instance Method Summary collapse
-
#initialize(encryption_key) ⇒ AES256CFBCIVScheme
constructor
A new instance of AES256CFBCIVScheme.
- #required_encryption_key_length ⇒ Object
- #streaming_decrypt(from_ciphertext_io:, into_plaintext_io: nil, &blk) ⇒ Object
- #streaming_decrypt_range(from_ciphertext_io:, range:, into_plaintext_io: nil, &blk) ⇒ Object
- #streaming_encrypt(into_ciphertext_io:, from_plaintext_io: nil, &blk) ⇒ Object
Methods inherited from BaseScheme
Constructor Details
#initialize(encryption_key) ⇒ AES256CFBCIVScheme
Returns a new instance of AES256CFBCIVScheme.
5 6 7 8 9 |
# File 'lib/block_cipher_kit/aes_256_cfb_civ_scheme.rb', line 5 def initialize(encryption_key, **) raise ArgumentError, "#{required_encryption_key_length} bytes of key material needed, at the minimum" unless encryption_key.bytesize >= required_encryption_key_length @iv = BlockCipherKit::KeyMaterial.new(encryption_key.byteslice(0, 16)) @key = BlockCipherKit::KeyMaterial.new(encryption_key.byteslice(16, 32)) end |
Instance Method Details
#required_encryption_key_length ⇒ Object
11 12 13 |
# File 'lib/block_cipher_kit/aes_256_cfb_civ_scheme.rb', line 11 def required_encryption_key_length 48 end |
#streaming_decrypt(from_ciphertext_io:, into_plaintext_io: nil, &blk) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/block_cipher_kit/aes_256_cfb_civ_scheme.rb', line 15 def streaming_decrypt(from_ciphertext_io:, into_plaintext_io: nil, &blk) cipher = OpenSSL::Cipher.new("aes-256-cfb") cipher.decrypt cipher.iv = @iv cipher.key = @key read_copy_stream_via_cipher(source_io: from_ciphertext_io, cipher: cipher, destination_io: into_plaintext_io, &blk) end |
#streaming_decrypt_range(from_ciphertext_io:, range:, into_plaintext_io: nil, &blk) ⇒ Object
31 32 33 34 35 |
# File 'lib/block_cipher_kit/aes_256_cfb_civ_scheme.rb', line 31 def streaming_decrypt_range(from_ciphertext_io:, range:, into_plaintext_io: nil, &blk) writable = BlockCipherKit::BlockWritable.new(into_plaintext_io, &blk) lens = BlockCipherKit::WriteWindowIO.new(writable, range.begin, range.end - range.begin + 1) streaming_decrypt(from_ciphertext_io: from_ciphertext_io, into_plaintext_io: lens) end |
#streaming_encrypt(into_ciphertext_io:, from_plaintext_io: nil, &blk) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/block_cipher_kit/aes_256_cfb_civ_scheme.rb', line 23 def streaming_encrypt(into_ciphertext_io:, from_plaintext_io: nil, &blk) cipher = OpenSSL::Cipher.new("aes-256-cfb") cipher.encrypt cipher.iv = @iv cipher.key = @key write_copy_stream_via_cipher(source_io: from_plaintext_io, cipher: cipher, destination_io: into_ciphertext_io, &blk) end |