Argon2Swift
public class Argon2Swift
Main class to handle all Argon2 hashing and verification
Usage Example
- Hash the password: “Password12”
let hashResult = try! Argon2Swift.hashPasswordString(password: "Password12", salt: Salt.newSalt())
let hashData = hashResult.hashData()
let base64Hash = hashResult.base64String()
let hexHash = hashResult.hexString()
let encodedData = hashResult.encodedData()
let encodedString = hashResult.encodedString()
-
Hashes a given
Stringpassword with Argon2 utilizing the given salt as well as optionally the specific parameters of the hashing operation itselfThrows
Argon2SwiftExceptionif the hashing fails in any mannerDeclaration
Swift
public static func hashPasswordString(password: String, salt: Salt, iterations: Int = 32, memory: Int = 256, parallelism: Int = 2, length: Int = 32, type: Argon2Type = .i, version: Argon2Version = .V13) throws -> Argon2SwiftResultParameters
passwordThe
Stringpassword to hash (utf-8 encoded)saltThe
Saltto use with Argon2 as the salt in the hashing operationiterationsThe amount of iterations that the algorithm should perform (optional parameter, defaults to 32)
memoryThe amount of memory the hashing operation can use at a maximum (optional parameter, defaults to 256)
parallelismThe factor of parallelism when comouting the hash (optional parameter, defaults to 2)
lengthThe length of the final hash (optional parameter, defaults to 32)
typeThe specific type of Argon2 to use, either
i,d, orid(optional parameter, defaults to.i)versionThe version of Argon2 to use in the hashing computation, either
V10orV13(optional parameter, defaults to.V13)Return Value
An
Argon2SwiftResultcontaining the hash, encoding, and convenience methods to access the hash and encoded results in various forms -
Hashes a given
Datapassword with Argon2 utilizing the given salt as well as optionally the specific parameters of the hashing operation itselfThrows
Argon2SwiftExceptionif the hashing fails in any mannerDeclaration
Swift
public static func hashPasswordBytes(password: Data, salt: Salt, iterations: Int = 32, memory: Int = 256, parallelism: Int = 2, length: Int = 32, type: Argon2Type = .i, version: Argon2Version = .V13) throws -> Argon2SwiftResultParameters
passwordThe
Datapassword to hashsaltThe
Saltto use with Argon2 as the salt in the hashing operationiterationsThe amount of iterations that the algorithm should perform (optional parameter, defaults to 32)
memoryThe amount of memory the hashing operation can use at a maximum (optional parameter, defaults to 256)
parallelismThe factor of parallelism when comouting the hash (optional parameter, defaults to 2)
lengthThe length of the final hash (optional parameter, defaults to 32)
typeThe specific type of Argon2 to use, either
i,d, orid(optional parameter, defaults to.i)versionThe version of Argon2 to use in the hashing computation, either
V10orV13(optional parameter, defaults to.V13)Return Value
An
Argon2SwiftResultcontaining the hash, encoding, and convenience methods to access the hash and encoded results in various forms -
Verifies a
Stringpassword with the given encodedString, returningtrueon successful verifications andfalseon incorrect ones.Throws
Argon2SwiftExceptionif the verification fails in any mannerDeclaration
Swift
public static func verifyHashString(password: String, hash: String, type: Argon2Type = .i) throws -> BoolParameters
passwordThe
Stringpassword to verify and check (utf-8 encoded)encodedThe
Stringencoded Argon2 value to check the password against (utf-8 encoded)typeThe specific type of Argon2 to use, either
i,d, orid(optional parameter, defaults to.i)Return Value
A
Boolsignifying whether the password is equivalent to the hash or not -
Verifies a
Datapassword with the given encodedData, returningtrueon successful verifications andfalseon incorrect ones.Throws
Argon2SwiftExceptionif the verification fails in any mannerDeclaration
Swift
public static func verifyHashBytes(password: Data, hash: Data, type: Argon2Type = .i) throws -> BoolParameters
passwordThe
Datapassword to verify and checkencodedThe
Dataencoded Argon2 value to check the password againsttypeThe specific type of Argon2 to use, either
i,d, orid(optional parameter, defaults to.i)Return Value
A
Boolsignifying whether the password is equivalent to the hash or not -
A method to map the
Argon2TypeSwift enum to theArgon2_typeC struct in the reference libraryDeclaration
Swift
static func getArgon2Type(type: Argon2Type) -> Argon2_typeParameters
typeThe
Argon2Typeto get the equivalentArgon2_typeforReturn Value
An
Argon2_typeobject to use in the C argon2 methods -
A method to set an
[Int8]mutable pointer that the C methods will modify with resultsDeclaration
Swift
static func setPtr(length: Int) -> UnsafeMutablePointer<Int8>Parameters
lengthThe length of the pointer to allocate
Return Value
An allocated
UnsafeMutablePointer<Int8>with the given length -
A method to deinitialize and deallocate an
Int8mutable pointer that has been already allocatedDeclaration
Swift
static func freePtr(pointer: UnsafeMutablePointer<Int8>, length: Int)Parameters
pointerThe
UnsafeMutablePointer<Int8>to deinitialize and freelengthThe length of the given pointer
Argon2Swift Class Reference