license and AES
This commit is contained in:
31
app/models/AESEncDec.rb
Normal file
31
app/models/AESEncDec.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
require 'openssl'
|
||||||
|
require 'base64'
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
|
class AESEncDec {
|
||||||
|
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||||
|
|
||||||
|
def export_key
|
||||||
|
ENV['aes_key'] = cipher.key = cipher.random_key # stores the key in key, and also sets the generated key on the cipher
|
||||||
|
ENV['aes_iv'] = cipher.iv = cipher.random_iv # stores the iv in iv, and also sets the generated iv on the cipher
|
||||||
|
end
|
||||||
|
|
||||||
|
def encrypt(data)
|
||||||
|
cipher.encrypt
|
||||||
|
cipher.key = ENV["aes_key"]
|
||||||
|
cipher.iv = ENV["aes_iv"]
|
||||||
|
encrypted = cipher.update(data) + cipher.final
|
||||||
|
encrypted = Base64.urlsafe_encode64(encrypted)
|
||||||
|
return encrypted
|
||||||
|
end
|
||||||
|
|
||||||
|
def decrypt
|
||||||
|
cipher.decrypt
|
||||||
|
cipher.key = ENV["aes_key"]
|
||||||
|
cipher.iv = ENV["aes_iv"]
|
||||||
|
|
||||||
|
# Start the decryption
|
||||||
|
decoded = Base64.urlsafe_decode64(encrypted)
|
||||||
|
decrypted = cipher.update(decoded) + cipher.final
|
||||||
|
end
|
||||||
|
}
|
||||||
@@ -12,7 +12,8 @@
|
|||||||
|
|
||||||
development:
|
development:
|
||||||
secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61
|
secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61
|
||||||
provision_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk
|
aes_key: <%= ENV['aes_key'] %>
|
||||||
|
aes_iv: <%= ENV['aes_iv'] %>
|
||||||
|
|
||||||
test:
|
test:
|
||||||
secret_key_base: 5c92143fd4a844fdaf8b22aba0cda22ef1fc68f1b26dd3d40656866893718ae5e58625b4c3a5dc86b04c8be0a505ec0ebc0be3bf52249a3d1e0c1334ee591cf0
|
secret_key_base: 5c92143fd4a844fdaf8b22aba0cda22ef1fc68f1b26dd3d40656866893718ae5e58625b4c3a5dc86b04c8be0a505ec0ebc0be3bf52249a3d1e0c1334ee591cf0
|
||||||
@@ -21,5 +22,6 @@ test:
|
|||||||
# instead read values from the environment.
|
# instead read values from the environment.
|
||||||
production:
|
production:
|
||||||
secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22
|
secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22
|
||||||
provision_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk
|
aes_key: <%= ENV['aes_key'] %>
|
||||||
|
aes_iv: <%= ENV['aes_iv'] %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
development:
|
development:
|
||||||
server_mode: cloud #local
|
server_mode: cloud #local
|
||||||
sx_provision_url: http://192.168.1.162:3005/api
|
sx_provision_url: http://192.168.1.162:3005/api
|
||||||
|
license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk
|
||||||
|
|
||||||
test:
|
test:
|
||||||
sx_provision_url: secure.smartsales.asia/api
|
sx_provision_url: secure.smartsales.asia/api
|
||||||
@@ -11,4 +11,5 @@ test:
|
|||||||
production:
|
production:
|
||||||
server_mode: cloud
|
server_mode: cloud
|
||||||
sx_provision_url: secure.smartsales.asia/api
|
sx_provision_url: secure.smartsales.asia/api
|
||||||
|
license_key: IAAXHpbSWAfvlWGYpDoXvZdmuRABNGk
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user