license cloud finished

This commit is contained in:
Yan
2017-12-08 16:26:41 +06:30
parent 33326931e2
commit dd5936b991
2 changed files with 19 additions and 26 deletions

View File

@@ -30,7 +30,7 @@ class MyAesCrypt
def export_to_file(passphrase)
file_path = "config/shops.json"
aes_key, aes_iv = export_key(passphrase)
tmpHash = {
tmpHash = {
"lookup" => passphrase,
"value" =>
{
@@ -40,27 +40,20 @@ class MyAesCrypt
}
shop_data = File.read(file_path)
if shop_data != ""
shop_json = JSON.parse(shop_data)
shop_json.each do |j|
byebug
if j == passphrase
j.each do |k|
return k["key"], k["iv"]
end
end
shop_json = JSON.parse(shop_data)
shop_json["data"].each do |j|
if j["lookup"] == passphrase
return j["value"]["key"], j["value"]["iv"]
end
shop_json << tmpHash
File.open(file_path, "w") { |io|
io.puts JSON.pretty_generate(shop_json)
}
else
File.open(file_path, "w") { |io|
io.write(tmpHash.to_json)
}
end
shop_json["data"] << tmpHash
File.open(file_path, "w") { |io|
io.puts JSON.pretty_generate(shop_json)
}
return aes_key, aes_iv
end