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

问题描述

我需要一些帮助,在iOS的WSSE头几代人。它使用它写在Symfony2中的应用的 SHA512 算法 5000次迭代连接code_as_bas​​e64 为真。对于移动应用程序,我发现这个问题编码的密码:这是可以做到同样的事情在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次迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 14:57