Where can I get CommonCrypto / CommonCrypto file from?

12,569

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
Share:
12,569
kimpro
Author by

kimpro

Updated on June 09, 2022

Comments

  • kimpro
    kimpro almost 2 years

    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?

  • m_katsifarakis
    m_katsifarakis over 5 years
    This won't work for a framework target. The error returned is: "Include of non-modular header inside framework module '<your_module>'".
  • sketchyTech
    sketchyTech over 5 years
    @m_katsifarakis I don't know whether this helps but Xcode 10 makes CommonCrypto available for import in Swift without the need for a bridging header.
  • m_katsifarakis
    m_katsifarakis over 5 years
    Yup, that's how I've done it too, but not all of my team can use it just yet.