Simple CommonCrypto wrapper for Swift for OS X, iOS, watchOS, and tvOS with Carthage support.
Released under the MIT license. Enjoy.
Carthage is the recommended way to install Crypto. Add the following to your Cartfile:
github "soffes/Crypto"
Currently, only digest and HMAC are supported.
There are extensions for NSData
and String
for convenience:
import Crypto
"sam".SHA1 // "f16bed56189e249fe4ca8ed10a1ecae60e8ceac0"
data.SHA1 // <NSData …>
MD2, MD4, MD5, SHA1, SHA224, SHA256, SHA384, SHA512 are available.
You can also use Digest
directly:
Digest.MD5(bytes: data.bytes, length: data.length) // [UInt8]
HMAC in CommonCrypto is also supported.
HMAC.sign(message: "sam", algorithm: .SHA1, key: "secret") // 1a90fa4e73686dfca75f5411d9fb81951edf1292
HMAC.sign(data: messageData, algorithm: .SHA1, key: keyData) // <NSData …>
MD5, SHA1, SHA224, SHA256, SHA384, SHA512 are the available algorithms.
It's worth noting, you can't directly use CommonCrypto
in Swift since Apple doesn't define a module for it. In the project, there are CommonCrypto
framework that wraps the libraries. This makes importing it into Swift as simple as
import CommonCrypto
If you want to use CommonCrypto
in your own project and don't care about my helper extensions, this is still the easiest way to use it. You can just include the CommonCrypto
framework and not the Crypto
framework to just use the wrapper.
This is a work in progress.
- Cryptor
- Digest
- HMAC
- Key Derivation
- Random
- Symmetric Key Wrap