Get Updates By E-mail 

Article Written By:
Johann Dowa

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


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments