Module: Eco::Data::Crypto

Defined in:
lib/eco/data/crypto/encryption.rb,
lib/eco/data/crypto.rb

Overview

TODO study how to encrypt uniquely the api key in the configuration file TODO study how RSA could boost team-shared Drive folder (updates, and people files should be encrypted via public key)

Defined Under Namespace

Classes: EncryptedData, OpenSSL

Constant Summary collapse

THIS_FILENAME =

file conf definitions

__FILE__
MY_NAME =

".rb"

File.basename(THIS_FILENAME, File.extname(THIS_FILENAME))
PATH =
File.dirname(THIS_FILENAME)
WORKING_DIR =
PATH + "/" + MY_NAME
PARSER_FILE =

.dll

WORKING_DIR + "/json_parser.json"

Class Method Summary collapse

Class Method Details

.decrypt(encrypted_data) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/eco/data/crypto/encryption.rb', line 292

def self.decrypt (encrypted_data)
  unless encrypted_data && encrypted_data.key && encrypted_data.iv
    return nil
  end
  cipher = OpenSSL::Cipher.new('aes-256-cbc')
  cipher.decrypt
  cipher.key = encrypted_data.key
  cipher.iv = encrypted_data.iv
  str_c = encrypted_data.content
  str = ""
  while str_c.length > 0
    str += cipher.update(str_c.slice!(0, 4096))
    #puts str[-50..-1] || str
  end
  str += cipher.final
  return str
end

.encrypt(str) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/eco/data/crypto/encryption.rb', line 278

def self.encrypt (str)
  cipher = OpenSSL::Cipher.new('aes-256-cbc')
  cipher.encrypt
  key = cipher.random_key
  iv = cipher.random_iv

  str_c = ""
  while str.length > 0
    str_c += cipher.update(str.slice!(0, 4096))
  end
  str_c += cipher.final
  EncryptedData.new({content: str_c, key: key, iv: iv})
end