问题
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?
回答1:
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
回答2:
In fact, you don't need to compile any file to using CommonCrypto, just import it in your project.
or using some wrapper in Swift, just like https://github.com/soffes/Crypto
Let's back to CommonCrypto file,Apple have released it's source code in https://opensource.apple.com/source/
来源:https://stackoverflow.com/questions/38584416/where-can-i-get-commoncrypto-commoncrypto-file-from