Get Updates By E-mail 

Article Written By:
Johann Dowa

Open Source Swift Library Providing Easy To Use Encrypt/Decrypt/Sign/Verify Security Functions

  •  
  •  
  •  
  •  
  •  

Late last year I mentioned a Swift library providing an easy to use wrapper of the Keychain API called KeychainSwiftAPI.

Here’s an open source library from Henri Normak called Heimdall wrapping many features of the iOS SDK’s C based libraries into neat Swift functions.

With Heimdall you can easily encrypt, decrypt, and sign strings and verify signatures.

This code snippet from the readme showing basic usage of Heimdall:

if let heimdall = Heimdall(tagPrefix: "com.example") {
    let testString = "This is a test string"

<pre><code>// Encryption/Decryption
if let encryptedString = heimdall.encrypt(testString) {
    println(encryptedString) // "cQzaQCQLhAWqkDyPoHnPrpsVh..."

    if let decryptedString = heimdall.decrypt(encryptedString) {
        println(decryptedString) // "This is a test string"
    }
}

// Signatures/Verification
if let signature = heimdall.sign(testString) {
    println(signature) // "fMVOFj6SQ7h+cZTEXZxkpgaDsMrki..."
    var verified = heimdall.verify(testString, signatureBase64: signature)
    println(verified) // True

    // If someone meddles with the message and the signature becomes invalid
    verified = heimdall.verify(testString + "injected false message",
                                signatureBase64: signature)
    println(verified) // False
}
</code></pre>

}

You can find Heimdall on Github here.

A nice straightforward Swift security library.


  •  
  •  
  •  
  •  
  •  

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