android - 如何在 iOS 中使用 WSSE 和 salted sha512 超过 1 次迭代

标签 android ios symfony sha512 wsse

我需要一些有关 iOS 中 WSSE header 生成的帮助。该应用程序是用 Symfony2 编写的,它使用 sha512 算法,5000 次迭代encode_as_base64 为真。对于移动应用程序,我发现了这个密码编码问题:SHA512 with salt for iOS虽然这只是一次迭代。使用包含最后一个循环的简单循环就足够了吗?

我们找到了 WSSE header 的 Android 生成代码:http://obtao.com/blog/2013/09/how-to-use-wsse-in-android-app/可以在 iOS 中做同样的事情,还是我们应该寻找另一种身份验证方式,比如 OAuth2?

最佳答案

如果你想通过 5000 次迭代重现与 Symfony2 相同的加密,你可以使用以下代码:

- (NSString *)hashPassword:(NSString *)password ansSalt:(NSString *)salt {

    NSString *passwordSalted = [NSString stringWithFormat:@"%@{%@}",password,salt];

    NSData *passwordData = [passwordSalted dataUsingEncoding:NSUTF8StringEncoding];

    uint8_t hash[CC_SHA512_DIGEST_LENGTH];
    CC_SHA512([passwordData bytes], [passwordData length], hash);

    NSMutableData *allData = [[NSMutableData alloc] init];
    [allData appendBytes:hash length:CC_SHA512_DIGEST_LENGTH];

    for (NSInteger i = 1; i < 5000; i++) {

        [allData appendBytes:[passwordData bytes] length:[passwordData length]];
        uint8_t hashLoop[CC_SHA512_DIGEST_LENGTH];
        CC_SHA512([allData bytes], [allData length], hashLoop);
        [allData setLength:0];
        [allData appendBytes:hashLoop length:CC_SHA512_DIGEST_LENGTH];

    }

    NSData *imageData = [NSData dataWithBytes:[allData bytes] length:[allData length]];

    return [imageData base64EncodedStringWithOptions:0];

}

不要忘记导入 CommonDigest.h:

#import <CommonCrypto/CommonDigest.h>

关于android - 如何在 iOS 中使用 WSSE 和 salted sha512 超过 1 次迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27983034/

相关文章:

android - 如何在我的应用程序中集成 ATOM 支付网关?

android - 如何知道OpenCv4Android native中是否使用了GPU计算

android - 使用相同的 key 签署两个应用程序

android - 处理程序数据 IO 吞吐量?

iphone - MPMoviePlayerController 上的专辑封面

ios - 应用程序被拒绝 - 启动时崩溃无法复制

ios - Flutter项目在ios13上运行

php - 如何从各种 Controller 访问进程对象

php - Symfony2/FOSUserBundle - 多个包的路由问题

node.js - 如何使用nodejs验证Symfony2 sha512密码