gpt4 book ai didi

ios - RNCryptor 密码加密

转载 作者:行者123 更新时间:2023-12-01 19:02:07 25 4
gpt4 key购买 nike

我以下面的代码为例。如果我错了,请帮助我。

- (void)storeToKeychain {

kPassword = [self computeSHA256DigestForString:[NSString stringWithFormat:@"%@%i%@", [username stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], pinHash, SALT_HASH];


NSData *data = [@"Data" dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSData *encryptedData = [RNEncryptor encryptData:data
withSettings:kRNCryptorAES256Settings
password:kPassword
error:&error];
}

- (NSString*)computeSHA256DigestForString:(NSString*)input {

const char *cstr = [input cStringUsingEncoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithBytes:cstr length:input.length];
uint8_t digest[CC_SHA256_DIGEST_LENGTH];

// This is an iOS5-specific method.
// It takes in the data, how much data, and then output format, which in this case is an int array.
CC_SHA256(data.bytes, data.length, digest);

// Setup our Objective-C output.
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];

// Parse through the CC_SHA256 results (stored inside of digest[]).
for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) {
[output appendFormat:@"%02x", digest[i]];
}

return output;
}

我的应用程序有一个设置和登录页面。每当用户创建帐户时,我希望将密码存储在加密的钥匙串(keychain)中,我可能应该使用用户名来增加安全性。所以我想在用户创建帐户时使用RNCryptor在钥匙串(keychain)中加密用户的用户名和密码。

我不确定 kPassword 使用什么密码在 RNEcryptor 方法中。我最初考虑使用由 UUID, username and a random 40 character salt hash 组成的 SHA256 哈希。将密码加密到钥匙串(keychain)中。后来我找到了 RNCryptor,我想知道是否可以改用 SHA256 hashkPassword还是有其他选择?

最佳答案

试试这个

https://github.com/Gurpartap/AESCrypt-ObjC 添加 AESCrypt-ObjC-master

现在将这些添加到顶部

#import "AESCrypt.h"

然后添加这些
NSString *message = @"yourStringtobeencrypted";
NSString *password = @"yourpassword";
NSString *encryptedData = [AESCrypt encrypt:message password:password];

你去吧..解密
NSString *message1 = [AESCrypt decrypt:encryptedData password:password];

:-)

关于ios - RNCryptor 密码加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22125118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com