IOS Processing PFX file

Source: Internet
Author: User
Tags pfx file

To popularize the basics, a PFX is a portable format that is specified by the public key encryption technology, standard 12th (Cryptography Standards #12, PKCS#12) for storing and transmitting user or server private keys, public keys, and certificates. It is a binary format, and these files are also called PFX files. See the Encyclopedia for details
My PFX file is provided by a colleague who writes C + +, which contains the secret key, which needs to be read first, then the data is Base64 encoded, and finally the string is obtained.

The first step is to drag the file into the project

Step Two, get the file path

The third step is to convert

The first step is to drag into the project directory as follows:

In the second step, get the file path:
This step requires attention, do not lazy use this way when getting the file path

NSString *filepath = [[NSBundle mainbundle] pathforresource:@ "myp12.pfx" oftype:nil];

To use

NSString *filepath = [[NSBundle mainbundle] pathforresource:@ "MYP12" oftype:@ "PFX"];

Otherwise, the file path is not obtained.

The third step is to convert

    * Transfer data
    //NSData *filedata = [NSData Datawithcontentsoffile:filepath];
    nsfilehandle* fh = [Nsfilehandle Filehandleforreadingatpath:filepath];
    NSData *filedata = [fh readdatatoendoffile];


    * Output
    nsstring *encodestring = [Filedata base64encodedstringwithoptions:0];
    Char *cstring = (char *) [encodestring utf8string];

Where Encodestring, CString is the result of conversion, encodestring corresponding OC string, CString corresponding C string.

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.