WeChat Payment (refund result notification) Golang AES-256-ECB decryption

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

AES-256-ECB decryption of the returned data is required to process the notification of the payment of the refund result, and the Golang standard library does not support AES ECB plus decryption, which is hereby recorded.

First, the way of decryption

The decryption steps are as follows

    1. Encrypt string A To do base64 decoding, get encrypted string b
    2. Do MD5 to merchant key, get 32 bit lowercase key* (key set path: Merchant Platform (pay.weixin.qq.com) –> account Settings –>api security –> key setting)
    3. Use key* to encrypt string B to do AES-256-ECB decryption

Second, Golang sample code

Package Mainimport ("Encoding/base64" "FMT" "Strings" "Github.com/nanjishidu/gomini/gocrypto") func main () {var (paykey = "ZIR0QKSTUFMOUOCHC9RFCDMFHECORQAP" Req_info = ' yywp8c48th0wnqztqei+41pflb26v+smfj9z6h9rpbgxtyzyxc+4ynez7qegznwj/ 6rib2mfywmzmcc41cfjksssoszpxxohuayb6kvnsz1p6frox1pdwzhyruxk7ounnd+gdsg4yz0xxzsl4/pynwllba/71qrnkj/ Bhcbyk4exnglju5dlup9pjqsntxjomi9rxu57m9jg5llqfxmwxyeaszjnvof0ulnhlwjsws4oxkokmw7veykylgv6npoom03qsx2wkrxlssa9gppg4hdareeu qh1fmbm7awjyrvyt/mezwg98p4gomeiyvz34xfdnctezx4bf/zislxt79ae1/ytzryfymxecrgjlbe0rg/t2ezjhac870u2vsvby1/ kce2a443n+denazixlbq1aewq3rqk/o6/tmm0lomzgctaoiamg+bh5+gu1uba9o3e+vehulydd5qx2o6i3+ qa9orbh415nyrrqdefq5vmcirikp5xyptwigza0tkoalkmpq4nde5gwhqibbgpfulzwoki+qjjhhbmwgbd6j0vqprorwouzc/ bhdkp72dcdncm7idupggnzbiy0+sewikcherykjge3ydhpjeqcqrah0cgxxhdt1xtbqbst1vqfyuhphujdxmxrknrgpn/oe1t0rlrq+78ci+ k8xe5e6seeuxqsee8r3358mpcdysmxwsxvzxk6er9ef98apqhwcndyejd2yych/mmvherux+7kjlrxsinuwa/cv/ Xakfquvuya5ea2eywtprha4dpyuf1snsaqvkfgqkxzrjhfagslvpsvqupx4zkkszhf4kwmzo3m7j1p94mxa7tm9mtojepoohpxeeb+m9rx6psfoi3mjdq5inj+vc4gokg/wd/lqiy6ttyp/dhdn6/v+aujx5axbo/ 2ndd3fwhhjkqekiuarr2clzt9zrqo4hkxdzo7cn06sgchk48tg8pmxnxkcmzm7aoquv5ymim2gwswirjhwj8cupafihc+gesdlbf6zbt+/ kxkafjaqq2rklen+wvz/zfz113epgwpjp16twboziq96mmekvwky/vdhjol8vftgh9f61oy1xwf6djtpw== ') b, err: = base64. Stdencoding.decodestring (req_info) if err! = Nil {fmt. Println (b, Err) Return}gocrypto. Setaeskey (Strings. ToLower (Gocrypto. MD5 (Paykey))) plaintext, err: = Gocrypto. Aesecbdecrypt (b) if err! = Nil {fmt. PRINTLN (Err) return}fmt. Println (String (plaintext))}

Iii. third-party library of Golang

Support common encryption and decryption

github.com/nanjishidu/gomini/gocrypto
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.