Skip to content

Lua version of the WeChat Message Cryptography

Notifications You must be signed in to change notification settings

TheNorthMemory/WXBizMsgCrypt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

WXBizMsgCrypt

the WeChat Message Cryptography in the openresty lua verison.

aes_pad.lua

extend the aes.lua with a set_padding method, discussing here

crypt.lua

encrypt(text, timestamp, nonce)

decrypt(text_encrypted)

get_sha1({token, timestamp, nonce, text_encrypted})

Synopsis

# nginx.conf:

server {
    location = /test {
        content_by_lua_block {
            local token = "pamtest"
            local aesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG"
            local timestamp = "1409304348"
            local nonce = "xxxxxx"
            local appId = "wxb11529c136998cb6"
            local sample = "<xml><ToUserName><![CDATA[oia2Tj我是中文jewbmiOUlr6X-1crbLOvLw]]></ToUserName><FromUserName><![CDATA[gh_7f083739789a]]></FromUserName><CreateTime>1407743423</CreateTime><MsgType><![CDATA[video]]></MsgType><Video><MediaId><![CDATA[eYJ1MbwPRJtOvIEabaxHs7TX2D-HV71s79GUxqdUkjm6Gs2Ed1KF3ulAOA9H1xG0]]></MediaId><Title><![CDATA[testCallBackReplyVideo]]></Title><Description><![CDATA[testCallBackReplyVideo]]></Description></Video></xml>"

            local crypt = require "resty.crypt"
            local wxmc = crypt:new(token, aesKey, appId)
            local encrypted = wxmc:encrypt(sample, timestamp, nonce)
            ngx.say("the sample encrypted: ", encrypted)

            local gsub = ngx.re.gsub
            sample = gsub(encrypted, [=[.*<Encrypt>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?</Encrypt>.*]=], "$1")
            ngx.say("the sample decrypted: ", wxmc:decrypt(sample))
        }
    }
}

About

Lua version of the WeChat Message Cryptography

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%