Android version Alipay integration get private key and public key

Source: Internet
Author: User
Tags openssl

The project needs to be integrated with the Alipay interface at the client. On the study: Because the use of Alipay interface, you need to pay Treasure Official website: Registered account, and apply. Here is the operation after the application is good. After the successful login, store my business services-under the page to find--> contract management-> find a dozen mobile payment-–> Click to download the integrated document-> jump to the new page, in the bottom of the page-> find download development package, download mobile payment can be. Then you will typically get three folders after extracting them.

This time to open the file name: Alipay Wallet Payment Interface Development Package 2.0 standard version of the file. There is a demo file after opening. Open the demo file. There will be three folders: the first OpenSSL; The second service-side demo, the third client demo. At this time, we need to be concerned with the OpenSSL file and the client demo file.

In the third demo file has the iOS version and the Android version of the demo. But when you deploy, you will find that you cannot run successfully. In the project master file, such a piece of code:

Merchant PID

public static final String PARTNER = "";

Merchant Collection Account

public static final String SELLER = "";

Merchant private key, PKCS8 format

public static final String rsa_private = "";

Pay Treasure Public key

public static final String rsa_public = "";

Because these, all need to according to the Merchant registration information to fill in. So even if you download the demo, there is no use. Here's how to get the private key and Alipay public key.

Remember the OpenSSL file we just pressured? The way to get the private key and public key is inside:

First open the OpenSSL file: The following is the file opening order: openssl–>bin–> Double-click Openssl.exe file. At this point a command box appears: (The first thing to note is that the file was opened under the Windows system) if the Apple system doesn't seem to be working. Then go on and say:

After opening the Command box: Enter the first line command to generate the private key as follows:

Genrsa-out RSA_PRIVATE_KEY.PEM 1024

Press ENTER, and then enter the second line of command to generate the public key:

Rsa-in Rsa_private_key.pem-pubout-out Rsa_public_key.pem

Press Enter and enter the third line to convert the RSA private key to PKCS8 format

Pkcs8-topk8-inform pem-in Rsa_private_key.pem-outform Pem-nocrypt

After the three line commands are executed, two files that end with:. PEM are generated. This is the public key and the private key that we generate. The file location is in: Bin directory. Of course we can't open these two files. But we can copy one to the desktop, change to TXT file open. Because all we need is a string inside, remember that when we reference these two long strings, we need to be aware of: strings, not including, wrapping, spaces, and other characters that are mistakenly added. So make sure to be careful when copying.

Of course, the private key is what we need the private key, how to get the Alipay public key it: back to Alipay first, first login,

One: click "View pid| KEY ", in the newly opened page (https://b.alipay.com/order/pidAndKey.htm), you can see the signing of payment treasure account number, Partner ID (PID).

Second: Enter payment password, query key, pay treasure public key.

Third: Upload the RSA public key, under the "Partner Key Management", click "RSA Encryption" after "Add encryption Key", the public key to copy in. Note that you cannot have spaces, change

Line or something like that.



: Click to confirm upload, if prompted upload success. is success.


This is the time to view the Alipay public key. As shown in figure:



At this point, the corresponding private key and the public key to fill the corresponding location of our demo can run. You can then integrate into the project. You need to do it yourself. Encounter problems, Baidu a bit. Hope to be of use to you.

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.