Module: Sinopac::FunBiz::Message
- Defined in:
- lib/sinopac/funbiz/message.rb
Class Method Summary collapse
Class Method Details
.decrypt(content:, key:, iv:) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/sinopac/funbiz/message.rb', line 21 def self.decrypt(content:, key:, iv:) cipher = OpenSSL::Cipher.new('AES-256-CBC') cipher.decrypt cipher.key = key cipher.iv = iv = cipher.update([content].pack('H*')) + cipher.final JSON.parse(, { symbolize_names: true }) end |
.encrypt(content:, key:, iv:) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/sinopac/funbiz/message.rb', line 11 def self.encrypt(content:, key:, iv:) cipher = OpenSSL::Cipher.new('AES-256-CBC') cipher.encrypt cipher.key = key cipher.iv = iv = cipher.update(content.to_json) + cipher.final .unpack('H*').first.upcase end |
.iv(nonce:) ⇒ Object
7 8 9 |
# File 'lib/sinopac/funbiz/message.rb', line 7 def self.iv(nonce:) Digest::SHA256.hexdigest(nonce).upcase[-16..] end |