Where can I get CommonCrypto / CommonCrypto file from?

kimpro picture kimpro · Jul 26, 2016 · Viewed 11.8k times · Source

I have a problem with importing CommonCrypto/CommonCrypto or CommonCrypto/CommonDigest. I need a SHA256 for my Swift code.

I found CommonCrypto github site in Cocoapods.

https://github.com/AlanQuatermain/aqtoolkit

So I have downloaded the file from above. But I'm getting errors about ARC (I have added Bridging-Header like other tutorials do.)
The header file's name is NSData+CommonCrypto.h and NSData+CommonCrypto.m.
It's not a CommonCrypto/CommonCrypto or CommonCrypto/CommonDigest Where can I download and get the exact file CommonCrypto for SHA256?

Answer

sketchyTech picture sketchyTech · Jul 26, 2016

No additional files are required. You need a bridging header first of all, which you already have but for those who don't the easiest way to achieve this is to add an Objective-C file to your project and to accept when it offers to create a bridging header. You can then either import the whole of CommonCrypto (thanks @zaph - see comments) to the bridging header:

#import <CommonCrypto/CommonCrypto.h>

Or the constituent parts:

#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonHMAC.h>
#import <CommonCrypto/CommonKeyDerivation.h>
#import <CommonCrypto/CommonSymmetricKeywrap.h>

You can now use CommonCrypto in Swift. For example code see here.

Edit

In Xcode 10 a bridging header is no longer required to import CommonCrypto in Swift. You can simply use:

import CommonCrypto