I have to check the suspect vehicles in South Africa, For this South Africa provides us with API. In API we have to pass a Driving license number or image that I am confused about.
In API we have to pass a hex-encoded binary string. See this URL: https://api.nptracker.co.za/docs/#/NPS-DL/NPS-DL
But this is not working (I am doing RSA public encryption with 128 bytes).
let gettBas64Text = self.getEncryptedPassword("02/0990016092185") debugPrint(gettBas64Text)
func getEncryptedPassword(_ getPass: String) -> String? {
let password = getPass
let publicKey:PublicKey!
let encrypted :EncryptedMessage
let clear:ClearMessage
do {
publicKey = try PublicKey(pemNamed: "public", in: .main)
do {
clear = try ClearMessage(string: password, using: .utf8)
do {
encrypted = try clear.encrypted(with: publicKey, padding: .PKCS1SHA256)
let base64String = encrypted.base64String
return base64String
}
catch{
print("Unable to start encrypted-- \(error)")
}
}
catch{
print("Unable to start clear")
}
}
catch{
print("Unable to start PublicKey-- \(error)")
}
return nil
}
static func getKeyStringFromPEM(name: String) -> String {
let bundle = Bundle.main
let keyPath = bundle.path(forResource: name, ofType: "pem")!
let keyString = try! String(contentsOfFile: keyPath, encoding: .utf8)
let keyArray = keyString.components(separatedBy: "\n") //Remove new line characters
var keyOutput : String = ""
for item in keyArray {
if !item.contains("-----") { //Example: -----BEGIN PUBLIC KEY-----
keyOutput += item //Join elements of the text array together as a single string
}
}
return keyOutput
}