I'm working on an app which uses CoreNFC to read the details of student ID cards.
The details I need to retrieve are stored on the card in an encrypted file and I need to use DES to decipher them.
I've been trying to use CommonCrypto to do this, but have been unable to get the CCCrypt() function working because it uses pointers and I'm coming at this from Swift.
The CCCrypt function takes eleven parameters. The last three are for the results of the decryption:
The details I need to retrieve are stored on the card in an encrypted file and I need to use DES to decipher them.
I've been trying to use CommonCrypto to do this, but have been unable to get the CCCrypt() function working because it uses pointers and I'm coming at this from Swift.
The CCCrypt function takes eleven parameters. The last three are for the results of the decryption:
dataOut is an UnsafeMutableRawPointer!
dataOutAvailable is an Int
dataOutMoved is an UnsafeMutablePointer<Int>!
Assuming you can supply all other parameters, you may need to write something like this:
Code Block var result = Data(count: maximumSizeOfDecryptedData) var numBytesDecrypted: Int = 0 let err = result.withUnsafeMutableBytes {bufPtr in CCCrypt(op, alg, options, key, keyLength, iv, dataIn, dataInLength, bufPtr.baseAddress, bufPtr.count, &numBytesDecrypted) } if err == kCCSuccess { result.count = numBytesDecrypted print(result) //<- Use `result` as the decrypted Data } else { print("error: \(err)") }