Hello I have an Objective-C project and I want to start using Apple’s CryptoKit framework. Is this possible?
Question posted in Xcode
Whether you're new to Xcode or an experienced developer, our archive has everything you need to know about this integrated development environment (IDE). From basic functionalities to advanced features, our archive covers a wide range of Xcode-related questions and answers. Browse our archive now and find solutions to your Xcode questions, and take your app development skills to the next level
Whether you're new to Xcode or an experienced developer, our archive has everything you need to know about this integrated development environment (IDE). From basic functionalities to advanced features, our archive covers a wide range of Xcode-related questions and answers. Browse our archive now and find solutions to your Xcode questions, and take your app development skills to the next level
2
Answers
Worked for me in straight C and, since Objective C is a strict superset, it should work.
I couldn’t find any direct documentation, but the header files themselves specify the parameters.
This is not CryptoKit, but unless you have an edge case it will work and is Apple supplied as opposed to openssl or libressl. Since OP mentioned it, I thought that was a reason for giving commoncrypto as an alternative. The actual implementation of the algorithms doesn’t differ in any significant way for most cases.
Late to answer, but IMHO it is easiest to create a Swift Static Library or a Swift Framework w/ Apple’s CryptoKit (dependency) and link it to your obj-c project. Then of course you’d import the Swift Static Lib/Framework headers into your Obj-C Class.
Be sure to prefix your Swift functions with
@objc open
for both your class and functions.I’d encourage you to use delegates, maybe some singleton pattern in your Swift CryptoKit Wrapper.
You can link your Swift Framework into your obj-c classes with a readonly property:
Since in the Swift Wrapper Class you have them set as open/obj-c prefix the funcs are exposed.
As a pseudo example, here is a Swift Func, and obj-c calling it.
Obj-c:
Swift class/func: