How do I obfuscate sensitive strings and API keys in Swift?

In Swift applications, it's important to obfuscate sensitive strings and API keys to protect them from unauthorized access. One common method is to use Base64 encoding or XOR encryption. Below is an example using simple Base64 encoding for obfuscation.

// String to be obfuscated let apiKey = "my_secret_api_key" // Obfuscating using Base64 encoding let data = apiKey.data(using: .utf8)! let base64Encoded = data.base64EncodedString() print("Obfuscated API Key: \(base64Encoded)") // To de-obfuscate: if let decodedData = Data(base64Encoded: base64Encoded) { let decodedString = String(data: decodedData, encoding: .utf8) print("De-obfuscated API Key: \(decodedString ?? "nil")") }

API Key Swift Obfuscation Encryption