Class: Reth::Keystore::AES128CTR
- Inherits:
-
Object
- Object
- Reth::Keystore::AES128CTR
- Defined in:
- lib/reth/keystore.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #decrypt(text, key) ⇒ Object
- #encrypt(text, key) ⇒ Object
-
#initialize(params = nil) ⇒ AES128CTR
constructor
A new instance of AES128CTR.
- #mkparams ⇒ Object
Constructor Details
#initialize(params = nil) ⇒ AES128CTR
Returns a new instance of AES128CTR.
38 39 40 41 |
# File 'lib/reth/keystore.rb', line 38 def initialize(params=nil) @name = 'aes-128-ctr' @params = params || mkparams end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
36 37 38 |
# File 'lib/reth/keystore.rb', line 36 def name @name end |
Instance Method Details
#decrypt(text, key) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/reth/keystore.rb', line 51 def decrypt(text, key) cipher = OpenSSL::Cipher.new name cipher.decrypt cipher.key = key cipher.iv = Utils.decode_hex(params[:iv]) cipher.update(text) + cipher.final end |
#encrypt(text, key) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/reth/keystore.rb', line 43 def encrypt(text, key) cipher = OpenSSL::Cipher.new name cipher.encrypt cipher.key = key cipher.iv = Utils.decode_hex(params[:iv]) cipher.update(text) + cipher.final end |
#mkparams ⇒ Object
59 60 61 |
# File 'lib/reth/keystore.rb', line 59 def mkparams {iv: Utils.encode_hex(SecureRandom.random_bytes(16))} end |