Extensive Open Source Swift Based Cryptography Helper Library (MD5, SHA1, SHA256)

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:

/* CryptoHash enum usage */
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

FacebookTwitterDiggStumbleUponGoogle Plus

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.

Leave a Reply

Your email address will not be published. Required fields are marked *