ios - Drupal 和 Objective C Base 64 不匹配

标签 ios drupal-7 base64 nsdata

我有这个字节序列(从 HTML 打印,因此对于丑陋的格式表示歉意)

193<br/>250<br/>194<br/>129<br/>62<br/>60<br/>12<br/>171<br/>199<br/>96<br/>13<br/>125<br/>166<br/>175<br/>80<br/>85<br/>137<br/>29<br/>15<br/>189<br/>33<br/>231<br/>237<br/>98<br/>165<br/>35<br/>75<br/>250<br/>181<br/>150<br/>35<br/>175<br/>129<br/>174<br/>13<br/>13<br/>121<br/>229<br/>30<br/>173<br/>112<br/>210<br/>2<br/>165<br/>110<br/>113<br/>141<br/>166<br/>102<br/>105<br/>33<br/>82<br/>220<br/>233<br/>118<br/>36<br/>73<br/>88<br/>196<br/>152<br/>15<br/>231<br/>164<br/>119<br/>

当我使用 Drupal 函数时:[_password_base64_encode][1] 我得到以下 base64 字符串:

/fjk/u1DAgulUpETay8IJZM5DoP6briMZCmGuLfZXwOUiqE1tJi5h0bo0IePlpcdaZK6GlRuqFGGMFAaDQCdr/

但是当我在 iOS 应用程序中使用这个字节序列时,代码如下:

NSString *base64Encoded = [hash base64EncodedStringWithOptions:0];

我得到:

wfrCgT48DKvHYA19pq9QVYkdD70h5+1ipSNL

为什么会出现这种行为?

谢谢

最佳答案

将函数_password_base64_encode移植到iOS:

- (NSString*)drupalBase64PasswordEncode:(NSData*)data {
    NSUInteger count = [data length];
    int i = 0;
    NSString *itTo64String = @"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    const char *itTo64 = [itTo64String cStringUsingEncoding:NSUTF8StringEncoding];
    char *input = [data bytes];
    NSMutableString *output = [[NSMutableString alloc] init];
    do {
        unsigned char value  = (unsigned char)input[i++];
        int value2;
        unsigned char toInsert = itTo64[value & 0x3f];
        [output appendString:[NSString stringWithFormat:@"%c" , toInsert]];
        if (i < count) {
            value2 = value | ((unsigned char)input[i] << 8);
        }
        toInsert = itTo64[(value2 >> 6) & 0x3f];
        [output appendString:[NSString stringWithFormat:@"%c" , toInsert]];
        if (i++ >= count) {
            break;
        }
        if (i < count) {
            value2 = value2 | ((unsigned char)input[i] << 16);
        }
        toInsert = itTo64[(value2 >> 12) & 0x3F];
        [output appendString:[NSString stringWithFormat:@"%c" , toInsert]];
        if (i++ >= count) {
            break;
        }
        toInsert = itTo64[(value2 >> 18) & 0x3F];
        [output appendString:[NSString stringWithFormat:@"%c" , toInsert]];
    }while(i < count);
    return output;
}

关于ios - Drupal 和 Objective C Base 64 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26626807/

相关文章:

jquery - AJAX 表单验证并提交

html - Drupal ckeditor 不支持某些 html 标签

perl - 如何使用 perl 转换 base64 编码的文件?

ios - 在 iPad 上的 UIWebView 中放置弹出框

ios - 触摸时更改 Sprite 图像

ios - 如何在 swift 中嵌入带有 Split View Controller 的选项卡栏 Controller ?

api - Youtube oEmbed API : 302, 然后 503 错误

android - 将位图转换为base64字符串并保存在共享首选项中

java - 将字节 slice 中的负数转换为 int

ios - plist 文件是否与应用程序包一起存储?