Class: Wechat::Callback::MessageDecryption
- Inherits:
-
Object
- Object
- Wechat::Callback::MessageDecryption
- Extended by:
- Wechat::Core::Common
- Defined in:
- lib/wechat/callback/message_decryption.rb
Overview
Message Decryption 是消息解密类。
Class Method Summary collapse
Class Method Details
.create(encoded_message, encoded_aes_keys) ⇒ Object
消息加解密 mp.weixin.qq.com/wiki/6/90f7259c0d0739bbb41d9f4c4c8e59a2.html
解密方式如下:
-
aes_msg = Base64_Decode(msg_encrypt)
-
rand_msg = AES_Decrypt(aes_msg)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wechat/callback/message_decryption.rb', line 16 def self.create(, encoded_aes_keys) assert_present! :encoded_message, assert_present! :encoded_aes_keys, encoded_aes_keys = Base64.decode64().bytes.inject('') do |buffer, byte| buffer += [ byte ].pack 'C' end aes_keys = encoded_aes_keys.map { |encoded_aes_key| Base64.decode64 "#{encoded_aes_key}=" } cipher = OpenSSL::Cipher::AES.new(256, 'CBC') cipher.decrypt cipher.padding = 0 cipher.key = aes_keys.first cipher.update()+cipher.final end |