iOS:NSString的可逆哈希?

时间:2013-04-08 11:30:15

标签: ios nsstring

我想用自己的自定义键在iOS上“哈希”一个字符串;重要的是做相反的事情,例如

NSString *secretWord = @"Hello World!";

secretWord = [self hashWithKey:@"customKey"];

// secret Word is now something unreadable, like 'kjwlekjfoaijfoijwef'

NSLog(@"%@", [secretWord unhashWithKey:@"customKey"]); // prints 'Hello World!'

我怎样才能达到这样的目标?

1 个答案:

答案 0 :(得分:4)

它不是散列(单向),而是你要求的加密。

您可以将RNCryptor用于此目的:https://github.com/rnapier/RNCryptor

如果(二进制)结果对您来说似乎不可读,并且您需要人类可读的内容,请尝试使用Base64编码。