Payment callback and verify login status Update time:06/02/2018
- RSA encryption is used in the interface of payment callback and login status verification for data transmission
- The system involves four RSA keys: MG public key, MG private key, developer public key and developer private key。
- The public key of MG will be disclosed to the developer, and the public key of the developer will be uploaded to MG through the developer background. MG's private key and developer's private key are reserved respectively。
- MG will use MG's private key and developer's public key to encrypt and decrypt data。
- Developers will use Mg's public key and developer's private key to encrypt and decrypt。
Developers generate RSA key
Build from website:http://web.chacuo.net/netrsakeypair(Or https://rsatool.org/)
If the developer server uses C# language, the private key needs to be converted to XML format, which can be converted online through the following tools。
http://superdry.apphb.com/tools/online-rsa-key-converter
Developers verify that the key pair is symmetric
Login website:http://tool.chacuo.net/cryptrsakeyvalid
Upload the public key in the key pair to the MG background
- Remove public key comments when uploading
- Remove the newline in the middle of the public key
- Check that the last character of the public key in the text box is not a newline
How to obtain MG public key
Log in the MG background, as shown in the figure above to obtain the MG public key. If the developer server uses C#language, the MG public key needs to be converted to XML format. In the example code, the converted public key is used。
Payment callback
- The payment callback has two parameters param_data and sign
- Param_data parameter is the data encrypted by MG's private key. Developers need to decrypt it with MG's public key
- The sign parameter is the data encrypted by the developer's public key. The developer needs to decrypt it with the developer's private key
- When decrypting, first get param_data and sign parameters, first line URLDecode (< b > < font color = "red" > some servers will automatically receive URLDecode, if it has been processed, this step can be omitted < / font > < b >), then base64decode, and then RSA decryption. When RSA decrypts, please use 128 bytes to decrypt (that is, decompose the parameter value according to 128 bytes for RSA decryption, and then splice the decrypted string). MG background has sample code for reference。
- Sample code download:
C#、
Java、
Php、
Nodejs、
Python
Example code description
Signin interface verification signature
- The developer's private key and MG's public key are used to verify the signature
- The data string is encrypted by MG's public key to get the parameter verify_data。
- The parameter verify_sign is obtained by encrypting the data string with the developer's private key。
- When encrypting, first RSA encryption, then base64encode, and then URLEncode. MG background has sample code for reference。
- Sample code download:
C#、
Java、
Php、
Nodejs、
Python
Example code description