Question:
Hi everyone.
I have used this site (http://travistidwell.com/jsencrypt/demo/index.html) to create RSA 2048 keys. When I try to use CkoPrivateKey to import the key, I keep getting an error. I have tried to load the PEM as a string using the 'loadPem' method and getting the actual data object from the PEM and loading as a DER using 'loadRSADer'.
To reproduce, go ahead and create a RSA-2048 key using the link provided above, then run that through CkoPrivateKey, like so:
NSString *myPEM = @"PUT_PRIVATE_KEY_PEM_HERE";
CkoPrivateKey *myPrivateKey = [CkoPrivateKey new];
BOOL success = [myPrivateKey LoadPem: myPEM];
if (!success) {
NSLog(@"%@", myPrivateKey.lastErrorText);
}
Can someone figure out what I'm doing wrong? Am I using the wrong method of CkoPrivateKey? Is there something wrong w/the RSA key I'm generating? Here is my error text:
ChilkatLog: LoadPem: DllDate: Jun 23 2014 ChilkatVersion: 9.5.0.40 UnlockPrefix: chilkatUnlockKey Architecture: Little Endian; 32-bit Language: IOS Objective-C VerboseLogging: 1 loadPem: Failed to convert from PEM to DER --loadPem Failed. --LoadPem --ChilkatLog
Thanks in advance.
I did not find a problem. I generated PEM from the site, and then in C++ did this:
bool RsaTesting::qa_loadPemPrivateKey(void) { const char *pem = "-----BEGIN RSA PRIVATE KEY-----\r\n\ MIICWwIBAAKBgHcbVK1yU0uXKeJL0jhUkaeT9GFDkbAUvxdp/wXqcY0nBGhcYBgJ\r\n\ aZ7IVSFjAWNreJbRyEmgoL8l3RnUtunDiJ2hHdMizE3KDcQEINOXl8kiLny1h/Iq\r\n\ X651izVrStmCnXxQi/wp0X4EfdlJcbB//f/Bxsfn1Pq35QU9Qkb8fdI5AgMBAAEC\r\n\ gYAXbvsj/OBCeQU2jrBXgNv/Wm60TDT3rb1DAAm6wjuBB/IoDjShxghPwx5sqSv2\r\n\ wYhCNBfx1HaL5QkxMdai+2N/SvrNrnFZRApV5K9GHAQpE7cNM/QEhukoJ4aTIJ8j\r\n\ Xaa/to2y04ZwjlmoD3ncLba6EvNjHjsr6GJB4YSV9RCgmQJBALrvtnuUzOHF1T+P\r\n\ FhScpvI6wl9zyRdunA5GNz9gi2M4h5VJyc9QvbyQnMaX1fsXseAZk57eenwqaDen\r\n\ s61GLt8CQQCjHFlh3ZHf/Wa/EP1qomc+IBqHnE+cxpo7dOhtY51TQFFYZXhVys4+\r\n\ HVCpF3zlLKv1BnejVVyLV0wj7oeF4lnnAkEAiSJDHyOIrXOgvZCtJQ/KVNaQMs/Q\r\n\ zFTDPKF79A1SE8arh/PqjSBxIDyCFhnayumV/o0kwx34gs/lRjbLU6ixxwJASQmO\r\n\ tJXklin/8hqHf1JNbLIvbv39YDRGJ82HrkPm1Lp+Mljtc20mwQWbcrwDvxMrxMIq\r\n\ nEbC89oZTBWpNbhPjQJATKyrMV4u+8DNOLin58VehcTTYvMeV/t0nDacj2cuf5hP\r\n\ OdePfxtjwwM7bEF3tRFxmDbsn+hJl0TdQVxUjgnZDQ==\r\n\ -----END RSA PRIVATE KEY-----";Here is the LastErrorText indicating success:CkPrivateKey key; bool success = key.LoadPem(pem); printf("%s\n",key.lastErrorText()); printf("qa_loadPemPrivateKey %s\n", success ? "success" : "failed" ); return success; }
ChilkatLog: LoadPem: DllDate: Jul 24 2014 ChilkatVersion: 9.5.0.41 UnlockPrefix: UNTTSTMAILQ Username: CHILKAT13:Matt Architecture: Little Endian; 32-bit Language: Visual C++ 11.0 (32-bit) VerboseLogging: 0 loadPem: loadPrivateKey: Loaded RSA DER --loadPrivateKey Verifying the DER... --loadPem Success. --LoadPem --ChilkatLogqa_loadPemPrivateKey success
A-ha! I see what happened. My application code was stripping out all the carriage returns from my keys before sending them to the 'loadPem' method. Fixed that in my code all is working. Thanks!!!