Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-06-2012, 04:07 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 1
ciso is on a distinguished road
Default Using CMS (PKCS7) of self compiled OpenSSL lib

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
ciso is offline   Reply With Quote
Reply

Bookmarks

Tags
cms, encrypt, ios, openssl, pkcs7

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 402
18 members and 384 guests
Alex-alex, Apptronics RBC, Atatator, chiataytuday, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, LunarMoon, MAMN84, n00b, pbart, reficul, Retouchable, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0