Module: GoSecure::SecureJson
- Defined in:
- lib/go_secure.rb
Class Method Summary collapse
- .db_encryption(bool) ⇒ Object
- .dump(obj) ⇒ Object
- .encrypted_dump(json) ⇒ Object
- .load(str) ⇒ Object
Class Method Details
.db_encryption(bool) ⇒ Object
144 145 146 |
# File 'lib/go_secure.rb', line 144 def self.db_encryption(bool) @db_encryption = !!bool end |
.dump(obj) ⇒ Object
158 159 160 161 162 |
# File 'lib/go_secure.rb', line 158 def self.dump(obj) json = Oj.dump(obj, mode: :compat) res = encrypted_dump(json) res end |
.encrypted_dump(json) ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/go_secure.rb', line 164 def self.encrypted_dump(json) if @db_encryption == false "**" + json else secret, salt = GoSecure.encrypt(json, "secure_json") salt + "--" + secret end end |
.load(str) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/go_secure.rb', line 148 def self.load(str) return nil unless str if str.match(/^\*\*/) Oj.load(str[2..-1], mode: :compat) else salt, secret = str.split(/--/, 2) Oj.load(GoSecure.decrypt(secret, salt, "secure_json"), mode: :compat) end end |