如何在iOS的咸SHA512使用WSSE超过1次迭代 [英] How to use WSSE in iOS with salted sha512 with more than 1 iteration

查看:289
本文介绍了如何在iOS的咸SHA512使用WSSE超过1次迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,在iOS的WSSE头几代人。它使用它写在Symfony2中的应用的 SHA512 算法 5000次迭代连接code_as_bas​​e64 为真。对于移动应用程序,我发现这个问题编码的密码: SHA512盐适用于iOS 虽然这只是一次迭代。用一个简单的循环,其中包括最后一个就足够了吗?

I need some help with WSSE Header generations in iOS. The application it's written in Symfony2 which uses sha512 algorithm with 5000 iterations and encode_as_base64 as true. For the mobile app, I found this question for encoding the password: SHA512 with salt for iOS although it's only one iteration. Using a simple loop which includes the last one would suffice it?

我们发现了Android一代WSSE头的code:的 http://obtao.com/blog/2013/09/how-to-use-wsse-in-android-app/ 这是可以做到同样的事情在iOS或我们应该找到认证另一种方式,像的OAuth2?

We found the code for the Android generation of the WSSE Headers: http://obtao.com/blog/2013/09/how-to-use-wsse-in-android-app/ It is possible to do the same thing in iOS or should we find another way for authentication, like OAuth2?

推荐答案

如果您想重现相同的加密作为Symfony2中的5000次迭代,你可以使用下面的code:

If you want to reproduce the same encryption as Symfony2 with the 5000 iterations, you can use the following code:

- (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:

Don't forgot to import CommonDigest.h:

#import <CommonCrypto/CommonDigest.h>

这篇关于如何在iOS的咸SHA512使用WSSE超过1次迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆