ser*_*gio 1 android sha512 symfony ios wsse
我在iOS中需要一些WSSE Header生成的帮助.它在Symfony2中编写的应用程序使用sha512算法,5000次迭代,encode_as_base64为true.对于移动应用程序,我发现这个问题用于编码密码:SHA512 with salt for iOS虽然它只是一次迭代.使用包含最后一个的简单循环就足够了吗?
我们找到了WSSE Headers的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];
}
Run Code Online (Sandbox Code Playgroud)
不要忘记导入CommonDigest.h:
#import <CommonCrypto/CommonDigest.h>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
636 次 |
| 最近记录: |