Class: DecodeWechatEncrypted
- Inherits:
-
Object
- Object
- DecodeWechatEncrypted
- Defined in:
- lib/wechat_data_crypt.rb
Instance Attribute Summary collapse
-
#appId ⇒ Object
Returns the value of attribute appId.
-
#sessionKey ⇒ Object
Returns the value of attribute sessionKey.
Instance Method Summary collapse
- #decryptData(encryptedData, iv) ⇒ Object
-
#initialize(appId, sessionKey) ⇒ DecodeWechatEncrypted
constructor
A new instance of DecodeWechatEncrypted.
Constructor Details
#initialize(appId, sessionKey) ⇒ DecodeWechatEncrypted
Returns a new instance of DecodeWechatEncrypted.
7 8 9 10 |
# File 'lib/wechat_data_crypt.rb', line 7 def initialize appId, sessionKey self.appId = appId self.sessionKey = sessionKey end |
Instance Attribute Details
#appId ⇒ Object
Returns the value of attribute appId.
6 7 8 |
# File 'lib/wechat_data_crypt.rb', line 6 def appId @appId end |
#sessionKey ⇒ Object
Returns the value of attribute sessionKey.
6 7 8 |
# File 'lib/wechat_data_crypt.rb', line 6 def sessionKey @sessionKey end |
Instance Method Details
#decryptData(encryptedData, iv) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |