Hi All,
I have issue with doing AES encryption with GCM Mode earlier using CBC which have to change to now GCM as change in backend system,
getting error "javax.crypto.AEADBadTagException: Tag mismatch!"
Code have used with AES/CBC encryption is :
Please Help!!
Hope have made my point Clear!!
Thanks In Advance !!
I have issue with doing AES encryption with GCM Mode earlier using CBC which have to change to now GCM as change in backend system,
getting error "javax.crypto.AEADBadTagException: Tag mismatch!"
Code have used with AES/CBC encryption is :
Code Block static func encryptsData(parameters: parameters?) -> (String, String) { // Convert Parameters in Json string var jsonStr = DefaultValues.empty do { if let str = String(data: try JSONSerialization.data(withJSONObject: parameters ?? [:], options: .prettyPrinted), encoding: .utf8) { jsonStr = str } } catch { debugPrint(error.localizedDescription) } // Get Secrete key, iv of 128 bits let iv = [UInt8](repeating: 0, count: 16) let randomStr = randomString(length: 16) let key: Array<UInt8> = Array(randomStr.utf8) // Encrypt Request Data with Secrete Key (AES) let aes = try! AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs5) let encrypted = try? aes.encrypt(Array(jsonStr.utf8)) if let encryptedMsg = encrypted { let encryptedData = Data(bytes: encryptedMsg, count: Int(encryptedMsg.count)) let encryptedBase64 = encryptedData.base64EncodedString() //Encrypt Secrete Key using Server Public key (RSA) let keyData = Data(bytes: key, count: key.count) let encryptedSceKey = encryptSecKeyWithPublickKey(key: String(data: keyData, encoding: .utf8) ?? "") return (encryptedBase64, encryptedSceKey) } return (DefaultValues.empty, DefaultValues.empty) }
Please Help!!
Hope have made my point Clear!!
Thanks In Advance !!