Hello,
I've compiled OpenSSL for the simulator and the armv6 and 7 device. This work quite well. I was able to deploy a small test app which uses a basic method from the lib to my iPad without any problems.
What I want to do now is to use the libraries implemented CMS (Cryptographic Message Syntax [1]) functionality.
To use the CMS_encrypt(...) method, I need a valid X.509 certificate which I've created outside my app, then a file which has to be encrypted and a symmetric cipher (I chose AES 128).
First I load my certificate and my file (which is just a plain text file) and convert it to a char* due OpenSSL's BIO object needs it in this way.
Code:
NSString *certificate = [self getContentsFromFile:@"user"
withFileExtension:@"crt"];
NSString *encryptData = [self getContentsFromFile:@"test"
withFileExtension:@"txt"];
const char *certBytes = [certificate UTF8String];
const char *dataBytes = [encryptData UTF8String];
Then I load the char*'s into a BIO and convert the certificates BIO into a X509 object.
Code:
BIO* bio = BIO_new_mem_buf((void*)certBytes, -1);
X509* cert = NULL;
PEM_read_bio_X509(bio, &cert, 0, NULL);
BIO *dataToEncrypt = BIO_new_mem_buf((void*)dataBytes, -1);
Then I create the symmetric cipher for the encrypt method...
Code:
const EVP_CIPHER *cipher = EVP_aes_128_cbc();
... and push the certificate on a X509 stack.
Code:
STACK_OF(X509) *certList;
certList = sk_new_null();
sk_X509_push(certList, cert);
And finally I use the CMS_encrypt() method to encrypt the file using the given cipher with a certain certificate.
Code:
CMS_ContentInfo *encryptedDataWithCMS = CMS_encrypt(certList, dataToEncrypt, cipher, NULL);
And now it becomes tricky... encryptedDataWithCMS is not null. This means the encrypt method was valid (I guess). But how can I get the content of encryptedDataWithCMS for example as a NSString or how can I save it into a file?
Does anyone have experience in using this?
Thanks,
Chris
[1] ...
Cryptographic Message Syntax - Wikipedia, the free encyclopedia