Hi team, i had this issue where my aesDecryt is not enconding to .utf8
staticfunc aesDecrypt(_ cadena: String, keySource: [UInt8], closure: @escaping (Bool, Any) -> Void) {
let bytesBase64 = Array.init(base64: cadena)
if bytesBase64.count > 0 {
let llave: Array = Array(keySource[0 ..< 16])
let valor: Array = Array(keySource[16 ..< 32])
let data: Array = Array(bytesBase64[16 ..< bytesBase64.count])
do {
let aes = try AES(key: llave, blockMode: CBC(iv: valor), padding: Padding.pkcs5)
let aesDecriptado = try aes.decrypt(bytesBase64)
if let cadena = String(bytes: aesDecriptado, encoding: .utf8) {
closure(true, cadena)
print("true response: \(cadena)")
} else {
closure(false, "Not valid string 1")
}
} catch {
closure(false, "decoding error: \(error).")
}
} else {
closure(false, "Not valid string 1")
}
}
this is how i call my method
let gID = "sPgFZceJ4Aqc8oiRIVlt8A=="
let KeysoruceByte = [112, 98, 90, 244, 255, 107, 76, 169, 120, 30, 16, 181, 121, 82, 54, 172, 122, 60, 165, 73, 8, 73, 169, 152, 209, 233, 67, 115, 77, 124, 47, 6, 111, 114, 197, 11, 58, 25, 3, 39, 203, 76, 155, 206, 195, 60, 176, 164, 251, 77, 54, 138, 6, 120, 43, 13, 43, 43, 16, 124, 64, 97, 179, 188]
SecurityMethods.aesDecrypt(gID ?? "", keySource: keySourceByte) { (response, idn) in
if response == true {
print("responde true")
DBManager.shared.deleteIDNEntity()
print("este es el idN: \(idn)")
if UserSingleton.getInstance().pushToken == ""{
self.firebaseToken.getIdN(self.application, callbackToken: self, cGoogleID: idn as! String)
}
why this is not a valid String
i had printed every param in my aes method
bytesBase64: [176, 248, 5, 101, 199, 137, 224, 10, 156, 242, 136, 145, 33, 89, 109, 240]
count: 16
llave: [112, 98, 90, 244, 255, 107, 76, 169, 120, 30, 16, 181, 121, 82, 54, 172]
valor: [122, 60, 165, 73, 8, 73, 169, 152, 209, 233, 67, 115, 77, 124, 47, 6]
data: []
valor aes CryptoSwift.AES
aesdecriptado: [150, 227, 55, 227, 153, 182, 70, 184, 10, 99, 8, 165, 193, 255, 74, 170]