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.