Swiftpack.co - Package - highmobility/hmcryptokit-swift

HMCryptoKit iOS SDK

The HMCryptoKit iOS SDK is a collection of cryptographic functions, centered around Elliptic Curve Cryptography, needed in HMKit and is based on Apple's Security and CommonCrypto libraries.

Security overview can be read here.

Table of contents


ECC: Uses well established Elliptic Curve Cryptography's curve p256 (that is as secure as RSA, while having a smaller footprint).

De-/Encrypt: Enables simple encryption and decryption with AES128.

Keys: Perform Diffie-Hellman's key exchange using X9.63 SHA256 algorithm. Additionally convert keys back and forth between bytes and Apple's SecKey format.

Random: Create pseudo-random bytes for cryptographic functions or as unique IDs.

Signatures: Create and verify Elliptic Curve Digital Signature Algorithm (ECDSA) X9.62 SHA256 or HMAC signatures.


It's recommended to use the library through Swift Package Manager (SPM), which is now also built-in to Xcode and accessible in File > Swift Packages > ... or going to project settings and selecting Swift Packages in the top-center.
When targeting a Swift package, the Package.swift file must include .package(url: "https://github.com/highmobility/hmcryptokit-swift", .upToNextMinor(from: "[__version__]")), under dependencies.

If SPM is not possible, the source can be downloaded directly from Github and built into an .xcframework using an accompaning script: XCFrameworkBuilder.sh. The created package includes both the simulator and device binaries, which must then be dropped (linked) to the target Xcode project.

Furthermore, when .xcframework is also not suitable, the library can be made into a fat binary (.framework) by running UniversalBuildScript.sh. This combines both simulator and device slices into one binary, but requires the simulator slice to be removed before being able to upload to App Store Connect – for this there is a AppStoreCompatible.sh script included inside the created .framework folder.


HMCryptoKit iOS SDK requires Xcode 11.0 or later and is compatible with apps targeting iOS 10.0 or above.


We would love to accept your patches and contributions to this project. Before getting to work, please first discuss the changes that you wish to make with us via GitHub Issues, Spectrum or Slack.

To start developing HMCryptoKit, please run git clone git@github.com:highmobility/hmcryptokit-swift.git and open the Xcode project (Xcode will handle the dependencies itself). Releases are done by tagged commits (as required by SPM, please read more about it here and here).

See more in CONTRIBUTING.md


This repository is using MIT license. See more in LICENSE


Stars: 0


Used By

Total: 0


- 2020-01-17 11:07:22


Added back scripts to deal with fat-binaries. Updated README.

- 2020-01-08 11:59:24

Updated dependencies.

- 2019-12-02 10:06:32

Found a workaround for iOS 13 shared key generation. Fixes a crash on pre-13 devices.

- 2019-10-29 12:36:53

Fixed shared key generation on iOS 13.0+

- 2019-10-15 11:45:20

Fix for signature creation (Collection's mutation error).

Proper Xcode 11 release.

- 2019-09-17 10:57:25

Updated for Xcode 11 GM2. Added XCFramework building script (and removed the "old" universal scripts). Removed the HMECKey typealias (use SecKey now) to make the XCFramework usable.

- 2019-09-11 13:23:12

Updated for Xcode 11 GM and Swift 5.1

- 2019-08-20 19:09:44

Updated for Xcode 11b6 to use with it's integrated SPM and Swift 5.1 Removed the CLT target for now.

- 2019-05-27 07:55:18

Fixed signature's out of bounds error (ArraySlice kept its old indices with a new Swift version / compiler).

- 2019-05-06 09:03:43

Fixed private key's .bytes output.

- 2019-05-02 12:16:19

Updated HMUtilities to 1.4.0

- 2019-03-29 07:47:22

Updated to Swift 5

- 2019-02-25 17:01:02

Updated dependencies.

- 2018-11-27 12:18:45

Refactored the signature methods (jwt and regular) to a single one, with an added optional parameter padded (defaults to true – as was before).

- 2018-11-22 11:45:24

Made SHA256 method public.
Added JWT message signing method (ES256).

- 2018-11-14 13:23:44

SPM improvements.

- 2018-11-06 11:49:59

Renamed ECKey to HMECKey.

- 2018-09-27 08:57:33

Proper Xcode 10, Swift 4.2 release.

- 2018-08-21 08:42:47

Updated to Swift 4.2

- 2018-05-29 11:01:00

Fixed HMAC and signature message padding when the message is an exact multiple of 64.

- 2018-04-12 17:19:57

Fixed invalid bundle-identifier and bitcode problems.

- 2018-04-03 08:19:24

Added CommonCrypto framework for easy access (when not using SPM to build this framework).

Initial release - 2018-04-03 08:15:59

New crypto framework for use in HMKit and other High-Mobility's frameworks (this replaces the old HMCrypto framework).