Class: Wechat::Callback::MessageEncryption
- Inherits:
-
Object
- Object
- Wechat::Callback::MessageEncryption
- Extended by:
- Wechat::Core::Common
- Defined in:
- lib/wechat/callback/message_encryption.rb
Overview
Message Encryption 是消息加密类。
Class Method Summary collapse
Class Method Details
.create(plain_text, encoded_aes_keys) ⇒ Object
消息加解密mp.weixin.qq.com/wiki/6/90f7259c0d0739bbb41d9f4c4c8e59a2.html
AES密钥:AESKey=Base64_Decode(EncodingAESKey + “=”),EncodingAESKey尾部填充一个字符的“=”, 用Base64_Decode生成32个字节的AESKey msg_encrypt=Base64_Encode(AES_Encrypt [random(16B)+ msg_len(4B) + msg + $AppId])
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wechat/callback/message_encryption.rb', line 14 def self.create(plain_text, encoded_aes_keys) assert_present! :plain_text, plain_text assert_present! :encoded_aes_keys, encoded_aes_keys cipher = OpenSSL::Cipher::AES.new(256, 'CBC') cipher.encrypt cipher.padding = 0 cipher.key = Base64.decode64 "#{encoded_aes_keys.first}=" Base64.encode64 cipher.update(plain_text)+cipher.final end |