我想用我自己的自定义 key 在 iOS 上“散列”一个字符串;重要的是也做相反的事情,例如
NSString *secretWord = @"Hello World!";
secretWord = [self hashWithKey:@"customKey"];
// secret Word is now something unreadable, like 'kjwlekjfoaijfoijwef'
NSLog(@"%@", [secretWord unhashWithKey:@"customKey"]); // prints 'Hello World!'
我怎样才能实现这样的目标?
最佳答案
这不是散列(这是单向的),而是您要求的加密。
您可以为此目的使用 RNCryptor:https://github.com/rnapier/RNCryptor
如果(二进制)结果对您来说似乎不可读,而您需要一些人类可读的内容,请尝试对其进行 Base64 编码。
关于iOS:NSString 的可逆散列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15877911/