I am trying to find a library to implement password hashing(with salt) using Scrypt algorithm. My question is similar to one already asked in stackoverflow (Hash password in Swift application)
I have found following two libraries in swift and objective c respectively but the hash string generated from these is not matching with the one generated at server.
- Swift-Sodium (https://github.com/jedisct1/swift-sodium)
- NAChloride (https://github.com/gabriel/NAChloride)
Can someone please help in finding library which can be used for Swift 3.0 iOS application for password hashing with salt.
Thank you.
Regards,
Nagraj Wadgire
Common Crypto contains PBKDF2 which is the NIST recommended password hashing function.
Example:
Password Based Key Derivation 2 (Swift 3)
Password Based Key Derivation can be used both for deriving an encryption key from password text and saving a password for authentication purposes.
There are several hash algorithms that can be used including SHA1, SHA256, SHA512 which are provided by this example code.
The rounds parameter is used to make the calculation slow so that an attacker will have to spend substantial time on each attempt. Typical delay values fall in the 100ms to 500ms, shorter values can be used if there is unacceptable performance.
This example requires Common Crypto
It is necessary to have a bridging header to the project:
#import <CommonCrypto/CommonCrypto.h>Add the
Security.frameworkto the project.Parameters:
Example usage:
Example Output: