Class: Eco::Data::Crypto::EncryptedData
- Inherits:
-
Object
- Object
- Eco::Data::Crypto::EncryptedData
- Defined in:
- lib/eco/data/crypto/encryption.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#iv ⇒ Object
readonly
Returns the value of attribute iv.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(init = {}) ⇒ EncryptedData
constructor
A new instance of EncryptedData.
- #load(file = nil) ⇒ Object
- #save(file = nil) ⇒ Object
Constructor Details
#initialize(init = {}) ⇒ EncryptedData
Returns a new instance of EncryptedData.
214 215 216 217 218 219 220 |
# File 'lib/eco/data/crypto/encryption.rb', line 214 def initialize(init = {}) @key = init[:key] @iv = init[:iv] @content = init[:content] @sha = sha256(@content) load() if !@key || !@iv end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
213 214 215 |
# File 'lib/eco/data/crypto/encryption.rb', line 213 def content @content end |
#iv ⇒ Object (readonly)
Returns the value of attribute iv.
213 214 215 |
# File 'lib/eco/data/crypto/encryption.rb', line 213 def iv @iv end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
213 214 215 |
# File 'lib/eco/data/crypto/encryption.rb', line 213 def key @key end |
Instance Method Details
#load(file = nil) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/eco/data/crypto/encryption.rb', line 221 def load (file = nil) parser = get_parser(file) sha64 = Base64.encode64(@sha) if @sha if parser.key?(sha64) #puts "found key!" = parser[sha64] key64, iv64 = .values_at("key", "iv") @key = Base64.decode64(key64) if key64 @iv = Base64.decode64(iv64) if iv64 else #puts "key not found! #{sha64}" end end |
#save(file = nil) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/eco/data/crypto/encryption.rb', line 234 def save (file = nil) parser = get_parser(file) sha64 = Base64.encode64(@sha) if @sha #puts "save key: #{sha64}" if parser.key?(sha64) = parser[sha64] else = {key: nil, iv: nil} parser[sha64] = end [:key] = Base64.encode64(@key) if @key [:iv] = Base64.encode64(@iv) if @iv set_parser(file, parser) end |