As per GDPR requirements, I am using Apple's built-in "Security" module to help with the encryption and decryption of information. I was able to generate my Private Key and Public Keys fairly easily using the documentation.
The problem I find myself at now is when trying to do encryption. In the Apple documentation I am following (found here), I was able to get to the SecKeyCreateEncryptedData function step. I run into errors on the line that says "plainText as CFData". Simply put, I am receiving a String object from a UITextField and properly retrieving the input text by adding the ".text" after my UITextField object.
When you do this, Xcode screams that a String object has to be forcibly downcast using "as!" if we want it as CFData. So I abided by Xcode, all to see that this does not work. I get "Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" on the line where documentation says "plainText as CFData". When I looked into it through the debugger, it was a whole bunch of assembly that's honestly just beyond me.
Regardless, this confuses me because if a String isn't the plainText the documentation is referring to, then what is? My instinct simply told me to do some research on what CFData is in Swift so that I could cast/create my String object into a CFData object, and simply pass that into the argument instead of needing to cast it within the function. That searching led me here, which then led me to what I believe is a good solution here. Now, I could be wrong that's a good work-around, but it's currently all I can think of. I'm stuck now trying to figure out what arguments I pass into the CFDataCreate function. I understand the types, but without any examples around really (not even in the documentation), I just can't figure out how to get it, or what to pass in, and how to get my String object in the proper format it needs.
Thank you for any help, and if you have questions for me, please ask