OpenSSL is the most powerful SSL and TLS library available which wraps a full cryptographic library. The library is written in pure C and due to its endless size and not-so-well-designed C interface it is very hard for beginners to step into it.
The aim of the MIHCrypto library is to provide an object-oriented interface which allows developers to write simple and clean code by still using the power of the OpenSSL libCrypto
library. OpenSSL is a very large library so (yet) not the whole library is wrapped by MIHCrypto. Since I am developing the library because personal needs focus of the functionallity is on modern cryptographic apporaches, but everybody is welcome to contribute other parts to the library.
CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like MIHCrypto in your projects.
platform :ios, '6.0'
pod "MIHCrypto", "~> 0.4.1"
MIHCrypto is based on some less protocol declarations (in MIHCrypto/Core
) and all ciphers are implementing these. So you have to use only a few interfaces for encrypting and decrypting with different cryptographic approaches.
id<MIHSymmetricKey> symmetricKey = ...
NSError *encryptionError = nil;
NSData *messageData = [@"My top secret message" dataByUsingEncoding:NSUTF8Encoding];
NSData *encryptedData = [symmetricKey encrypt:messageData error:&encryptionError];
These keys are either loaded from a file or generated by using an implementation of MIHKeyFactory
.
MIHAESKeyFactory *factory = [[MIHAESKeyFactory alloc] init];
id<MIHSymmetricKey> aesKey = [factory generateKey];
If you need more sample code have a look at the unit tests or have a look at the docs.
MIHCrypto is based on 5 core protocols which are implemented by various algorithms and approaches.
MIHKeyFactory
- used to generate new keysMIHSymmetricKey
- represents a symmetric key (like AES or DES) and can be used to encrypt and decrypt dataMIHPublicKey
- represents a public key (like RSA PUBKEY) and can be used to encrypt data and to verify a signatureMIHPrivateKey
- represents a private key (like RSA private key) and can used to decrypt data and to sign a messageMIHHashAlgorithm
- represents a hash funtion and only has one method to create the hash sum of the passed data
MIHCrypto requires Xcode 4 and above, targeting either iOS 5.0 and above, or Mac OS 10.7 Mountain Lion (64-bit with modern Cocoa runtime) and above.
As already mentioned OpenSSL is very powerful and large project so this library doesn't support all functionallity of it yet and new functions are added as needed. At the moment following cryptographic approaches are supported:
- AES (block cipher)
- BIGNUM (discrete mathematics)
- DES (block cipher)
- MD5 (hash algorithm)
- RSA (public-key cryptography)
- SHA, SHA256, SHA384, SHA512 (hash algorithm)
Following approaches are in progress and may get published shortly:
- ECC (public-key cryptography)
Anybody is welcome to add additional support for other approaches.
MIHCrypto is available under the MIT license. See the LICENSE file for more info.