Cyrus
Cyrus

Reputation: 3717

Encoding/Decoding using NSData+Base64.h

I have some encrypted data that I'm converting to a base64. I am having difficulty converting that string back into NSData that I can then use for decryption.

NSData *encryptedData = [self encrypt:_secretData key:[self md5data:_key] padding:&padding];
//I've tried this with different data too
NSString *cyphertext = [encryptedData base64EncodingWithLineLength:0];
//this works fine
[cyphertext dataUsingEncoding:NSUTF8StringEncoding]; 
//this returns too many bytes ... it's longer than my original data

I'm using the standard "NSData+Base64.h" by Dave Winer - I found it on github.

Any tips on how to convert the string back to the same NSData object?

Upvotes: 1

Views: 1778

Answers (1)

Vincent Guerci
Vincent Guerci

Reputation: 14419

using its counterparts maybe?

 + (NSData *) dataWithBase64EncodedString:(NSString *) string

Note that converting to base64 must brings a multiple of 4...

Upvotes: 3

Related Questions