func decryptPushNotificationPayload()

in sdk/communication/AzureCommunicationChat/Source/NotificationUtils/CryptoUtils.swift [104:143]


func decryptPushNotificationPayload(cipherText: [UInt8], iv: [UInt8], cryptoKey: String) throws -> String {
    guard let decodedData = Data(base64Encoded: cryptoKey) else {
        throw AzureError
            .client(
                "Failed to initialize a data object with the given cryptoKey. Please ensure the cryptoKey is a Base64 encoded string."
            )
    }

    let keyBytes = Array(decodedData)

    let cryptLength = size_t(cipherText.count + kCCBlockSizeAES128)
    var cryptData = [UInt8](repeating: 0, count: cryptLength)

    let keyLength = size_t(kCCKeySizeAES256)
    let algoritm: CCAlgorithm = UInt32(kCCAlgorithmAES)
    let options: CCOptions = UInt32(kCCOptionPKCS7Padding)

    var numBytesEncrypted: size_t = 0

    let cryptStatus = CCCrypt(
        CCOperation(kCCDecrypt),
        algoritm,
        options,
        keyBytes,
        keyLength,
        iv,
        cipherText,
        cipherText.count,
        &cryptData,
        cryptLength,
        &numBytesEncrypted
    )
    if UInt32(cryptStatus) == UInt32(kCCSuccess) {
        cryptData.removeSubrange(numBytesEncrypted ..< cryptData.count)
    } else {
        throw AzureError.client("Error in decrypting Notification Payload: \(cryptStatus)")
    }

    return String(decoding: cryptData, as: UTF8.self)
}