I'm supposed to encrypt some data with a string public key sent from a server through HTTPS and send back to the server.
I did a lot of research and also studied these topics plus a lot of other things related to it but couldn't solve my problem.
All I'm saying is that I cannot convert a string to a seckey to use this function.
func SecKeyEncrypt(_ key: SecKey,
_ padding: SecPadding,
_ plainText: UnsafePointer<UInt8>,
_ plainTextLen: Int,
_ cipherText: UnsafeMutablePointer<UInt8>,
_ cipherTextLen: UnsafeMutablePointer<Int>) -> OSStatus
1-how to encrypt and decrypt a String(Plain Text) with RSA public key in ios, swift
This is MyCode for encryption:
let publickey : SecKey = "# -----BEGIN PUBLIC KEY----- some key ----
END PUBLIC KEY----- #" as! SecKey
let message = "plain text"
let blockSize = SecKeyGetBlockSize(publicKey!)
var messageEncrypted = [UInt8](repeating: 0, count: blockSize)
var messageEncryptedSize = blockSize
var status: OSStatus!
status = SecKeyEncrypt(publickey!, SecPadding(rawValue: 0), message,
message.characters.count, &messageEncrypted, &messageEncryptedSize)
app get crashed at the first line.