Reputation: 17349
I'd like to 'hash' a string on iOS with my own custom key; important is to do the opposite as well, e.g.
NSString *secretWord = @"Hello World!";
secretWord = [self hashWithKey:@"customKey"];
// secret Word is now something unreadable, like 'kjwlekjfoaijfoijwef'
NSLog(@"%@", [secretWord unhashWithKey:@"customKey"]); // prints 'Hello World!'
How can I achieve something like this?
Upvotes: 0
Views: 356
Reputation: 25144
It's not hashing (which is one-way), but encryption you're asking for.
You can use RNCryptor for this purpose: https://github.com/rnapier/RNCryptor
If the (binary) result seems unreadable to you and you need something human-readable, try Base64-encoding it.
Upvotes: 4