十六进制字符串检测为Base64

时间:2015-05-19 12:02:30

标签: ios hex base64 nsdata

我将Hex字符串传递给此方法,但它仍将字符串检测为base64。 我的字符串是:546869732069732073696d706c6520737472696e672e

+(BOOL)isBase64Data:(NSString *)input
    {
        input=[[input componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsJoinedByString:@""];
     if ([input length] % 4 == 0) {
        static NSCharacterSet *invertedBase64CharacterSet = nil;
        if (invertedBase64CharacterSet == nil) {
            invertedBase64CharacterSet = [[NSCharacterSet
                                            characterSetWithCharactersInString:
                                                @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="]
                                           invertedSet];
        }
        BOOL isbase64 = [input rangeOfCharacterFromSet:invertedBase64CharacterSet
                                               options:NSLiteralSearch].location   == NSNotFound;

    return isbase64;
}
return NO;
}

在网上有几个链接,上面的代码标记为true。但不知何故,它不能使用我提供的字符串。

0 个答案:

没有答案