update client key encryption
This commit is contained in:
@@ -26,9 +26,8 @@ class ClientsController < ApplicationController
|
||||
def create
|
||||
@client = Client.new(client_params)
|
||||
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||
key=cipher.random_key
|
||||
secrect_key= Base64.encode64(key)
|
||||
@client.secrect_key=secrect_key
|
||||
secrect_key = cipher.random_key
|
||||
@client.secrect_key = secrect_key
|
||||
|
||||
respond_to do |format|
|
||||
if @client.save
|
||||
|
||||
@@ -140,14 +140,11 @@ class BatchLineItem < ApplicationRecord
|
||||
end
|
||||
end
|
||||
def self.encrypted(message,encrypt_key)
|
||||
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
|
||||
cipher = OpenSSL::Cipher.new("aes-256-cbc")
|
||||
cipher.encrypt
|
||||
|
||||
key = Digest::SHA1.hexdigest(encrypt_key)
|
||||
iv =encrypt_key
|
||||
|
||||
cipher.key = encrypt_key
|
||||
cipher.iv = encrypt_key
|
||||
cipher.iv = encrypt_key[0,16]
|
||||
|
||||
encrypted = cipher.update(message)
|
||||
encrypted << cipher.final
|
||||
|
||||
@@ -3,4 +3,12 @@ class Client < ApplicationRecord
|
||||
validates :name, :uniqueness => {:message =>"This client name is already taken." } ,on: :create
|
||||
validates :location_code ,presence: { message: "Please enter client location code." }
|
||||
validates :location_code, :uniqueness => {:message =>"This location code is already taken." } ,on: :create
|
||||
|
||||
def secrect_key
|
||||
Base64.decode64(super)
|
||||
end
|
||||
|
||||
def secrect_key=(value)
|
||||
super(Base64.encode64(value))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user