Class: Reth::Keystore::AES128CTR

Inherits:
Object
  • Object
show all
Defined in:
lib/reth/keystore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#mkparamsObject



59
60
61
# File 'lib/reth/keystore.rb', line 59

def mkparams
  {iv: Utils.encode_hex(SecureRandom.random_bytes(16))}
end