++ (id)dataWithBase64:(NSString *)base64 {
+ return [[[self alloc] initWithBase64:base64] autorelease];
+}
+
+- (id)initWithBase64:(NSString *)base64 {
+ BIO *mem = BIO_new_mem_buf((void *)[base64 cString], [base64 cStringLength]);
+ BIO *b64 = BIO_new(BIO_f_base64());
+ BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
+ mem = BIO_push(b64, mem);
+
+ NSMutableData *data = [NSMutableData data];
+ char inbuf[512];
+ int inlen;
+ while ((inlen = BIO_read(mem, inbuf, sizeof(inbuf))) > 0) {
+ [data appendBytes:inbuf length:inlen];
+ }
+
+ BIO_free_all(mem);
+ return [self initWithData:data];
+}
+