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.

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

©2015 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 *