我一直在用头撞墙,我一定错过了什么。在我对一些加密文本进行 base64 编码之后,就会调用此代码。在我调用 NSLog 签名的地方总是有效的。然而,有时其余的效果很好,而其他时候 removePlus 或 finalSig 则返回 null。此外,我使用的是 Xcode 4.5、ios6,并且我为该项目启用了 ARC。我觉得可能有些东西在我想要之前就自动发布了,或者类似的东西。如果有人有任何想法,我们将不胜感激。
// Get the data out of the context
char *outputBuffer;
long outputLength = BIO_get_mem_data(context, &outputBuffer);
NSMutableString *signature = [[NSMutableString alloc] init];
[signature appendString:[NSMutableString stringWithCString:outputBuffer encoding:NSASCIIStringEncoding]];
NSLog(@"Base64 Pre Encoded: %@", signature);
signature = [[signature stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding] mutableCopy];
NSMutableString *removePlus = [[signature stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"] mutableCopy];
NSString *finalSig = [removePlus stringByReplacingOccurrencesOfString:@"=" withString:@"%3D"];
//now we create the url request portion
NSMutableString *variables = [[NSMutableString alloc] init];
//set the variables we're going
[variables appendString:finalSig];