Yesterday I mentioned a nice Swift library for working with dates.
Here’s an open source Swift library providing a number of helper functions and extensions for cryptography called CryptoSwift from Marcin Krzyzanowski.
Specifically CryptoSwift makes it easy to hash and unhash MD5, SHA1, and SHA256 data. The library is pretty extensive, and you’ll need to look through the code to find everything.
This example modified from the readme shows the enum usage, direct method, and string methods for hashing data:
var data:NSData = NSData(bytes: [49, 50, 51] as [Byte], length: 3)
if let data = CryptoHash.md5.hash(data) {
println(data.hexString)
}
/* Direct methods */
let hash = MD5(data).calculate()
let hash = data.md5()
let hash = data.sha1()
let hash = data.sha256()
println(hash.hexString)
/* Hashing A String And Printing Result */
if let hash = "123".md5() {
println(string.md5())
}
You can find CryptoSwift on Github here.
A nice set of cryptography helpers.
See More: Swift Resources
- Dead Simple Library For Creating MD5, SHA1, And SHA256 Hashes From NSData and NSString Objects
- Extensive Swift Based Helper Library For Working With Dates
- Open Source Functional Programming Toolbelt For Swift Inspired By The Underscore.js Library
- Extensive Open Source Swift Based Core Data Wrapper With A MagicalRecord And Linq Inspired Syntax
- Extensive Swift Utility Library Inspired By Python’s Standard Library
Original article: Extensive Open Source Swift Based Cryptography Helper Library (MD5, SHA1, SHA256)
©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.