class DecodeWechatEncrypted

Attributes

appId[RW]
sessionKey[RW]

Public Class Methods

new(appId, sessionKey) click to toggle source
# File lib/wechat_data_crypt.rb, line 7
def initialize appId, sessionKey
  self.appId = appId
  self.sessionKey = sessionKey
end

Public Instance Methods

decryptData(encryptedData, iv) click to toggle source
# File lib/wechat_data_crypt.rb, line 12
def decryptData encryptedData, iv
  sessionKey = Base64.decode64(self.sessionKey)
  encryptedData = Base64.decode64(encryptedData)
  iv = Base64.decode64(iv)
  cipher = OpenSSL::Cipher.new("AES-128-CBC")
  cipher.decrypt
  cipher.key = sessionKey
  cipher.iv = iv

  result = cipher.update(encryptedData) + cipher.final
  JSON.parse result
end