Class: CryptoToolchain::BlackBoxes::RSAUnpaddedMessageRecoveryOracle
- Defined in:
- lib/crypto_toolchain/black_boxes/rsa_unpadded_message_recovery_oracle.rb
Instance Attribute Summary collapse
-
#keypair ⇒ Object
readonly
Returns the value of attribute keypair.
Instance Method Summary collapse
- #encrypt(ciphertext) ⇒ Object
- #execute(ciphertext) ⇒ Object
-
#initialize(keypair: CryptoToolchain::BlackBoxes::RSAKeypair.new) ⇒ RSAUnpaddedMessageRecoveryOracle
constructor
A new instance of RSAUnpaddedMessageRecoveryOracle.
Constructor Details
#initialize(keypair: CryptoToolchain::BlackBoxes::RSAKeypair.new) ⇒ RSAUnpaddedMessageRecoveryOracle
Returns a new instance of RSAUnpaddedMessageRecoveryOracle.
7 8 9 10 |
# File 'lib/crypto_toolchain/black_boxes/rsa_unpadded_message_recovery_oracle.rb', line 7 def initialize(keypair: CryptoToolchain::BlackBoxes::RSAKeypair.new) @keypair = keypair @seen = [] end |
Instance Attribute Details
#keypair ⇒ Object (readonly)
Returns the value of attribute keypair.
5 6 7 |
# File 'lib/crypto_toolchain/black_boxes/rsa_unpadded_message_recovery_oracle.rb', line 5 def keypair @keypair end |
Instance Method Details
#encrypt(ciphertext) ⇒ Object
19 20 21 |
# File 'lib/crypto_toolchain/black_boxes/rsa_unpadded_message_recovery_oracle.rb', line 19 def encrypt(ciphertext) keypair.encrypt(ciphertext, to: keypair.public_key) end |
#execute(ciphertext) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/crypto_toolchain/black_boxes/rsa_unpadded_message_recovery_oracle.rb', line 12 def execute(ciphertext) hsh = Digest::SHA256.hexdigest(ciphertext) raise ArgumentError.new("Already decrypted") if @seen.include?(hsh) @seen << hsh keypair.decrypt(ciphertext) end |