mihcrypto

Welcome to the documentation for the MIHCrypto library. This library provides a set of cryptographic utility functions for use in iOS and macOS development. Whether you need to encrypt data, generate hashes, or work with digital signatures, MIHCrypto has you covered.

Installation

To begin using MIHCrypto in your project, you can either manually add the library or use a dependency manager like CocoaPods or Carthage.

Manual Installation

  1. Download the MIHCrypto repository from GitHub.
  2. Drag and drop the MIHCrypto folder into your Xcode project.
  3. Make sure “Copy items if needed” is selected.
  4. Add `import MIHCrypto` to the top of your source files.

CocoaPods Installation

  1. Open your Podfile and add the following line: pod 'MIHCrypto'.
  2. Run pod install in your project directory.
  3. Make sure to include import MIHCrypto in your source files.

Carthage Installation

  1. Create a Cartfile and add the following line: github "subc/nanopb".
  2. Run carthage update to fetch and build the dependencies.
  3. In the “Build Phases” tab of your application target, add the MIHCrypto.framework to “Linked Frameworks and Libraries”.
  4. Make sure to include import MIHCrypto in your source files.

Usage

Encryption

The MIHCrypto library provides various encryption algorithms to secure your data. Here’s an example of how to encrypt a string using AES:


“`swift
import MIHCrypto

func encryptData() {
let key = AES.key(forPassword: “encryption_key”)
let dataToEncrypt = “Hello, World!”.data(using: .utf8)

if let encryptedData = AES.encrypt(dataToEncrypt, key: key) {
// Handle encrypted data
} else {
// Encryption failed
}
}
“`

Hashing

MIHCrypto allows you to generate various hash functions for data integrity. Here’s an example of generating an SHA-256 hash:


“`swift
import MIHCrypto

func generateHash() {
let dataToHash = “Hello, World!”.data(using: .utf8)

if let hash = Hash.sha256(dataToHash) {
// Handle hash
} else {
// Hash generation failed
}
}
“`

Digital Signatures

MIHCrypto enables the creation and verification of digital signatures. Here’s an example of signing and verifying data using RSA:


“`swift
import MIHCrypto

func signAndVerifyData() {
let privateKey = RSA.PrivateKey(pem: “private_key”)
let publicKey = RSA.PublicKey(pem: “public_key”)
let dataToSign = “Hello, World!”.data(using: .utf8)

if let signature = RSA.sign(dataToSign, privateKey: privateKey) {
// Handle signature

let isVerified = RSA.verify(dataToSign, signature: signature, publicKey: publicKey)
// Handle verification result
} else {
// Signature generation failed
}
}
“`

Conclusion

MIHCrypto provides a powerful set of cryptographic functions to ensure the security and integrity of your iOS and macOS applications. Whether you need encryption, hashing, or digital signatures, this library is designed to simplify the process and keep your data safe. Explore the library’s documentation for a complete list of available functions and for more advanced usage examples.