module Sygna::PrivateInfo

Public Class Methods

decode(data) click to toggle source
# File lib/sygna/private_info.rb, line 13
def self.decode(data)
  config = Sygna::Config.instance
  private_key = OpenSSL::PKey::EC.new(config.private_key)

  crypt.decrypt(private_key, [data].pack("H*"))
end
encode(data, public_key_hex) click to toggle source
# File lib/sygna/private_info.rb, line 3
def self.encode(data, public_key_hex)
  group = OpenSSL::PKey::EC::Group.new('secp256k1')
  key = OpenSSL::PKey::EC.new(group)
  public_key_bn = OpenSSL::BN.new(public_key_hex, 16)
  public_key = OpenSSL::PKey::EC::Point.new(group, public_key_bn)
  key.public_key = public_key

  crypt.encrypt(key, data.to_json).unpack('H*').first
end

Private Class Methods

crypt() click to toggle source
# File lib/sygna/private_info.rb, line 20
def self.crypt
  Crypt.new(cipher: "AES-256-CBC", digest: "SHA512", mac_digest: "SHA1")
end