Swift macros for string obfuscation to protect sensitive data from binary analysis.
ObfuscateMacro transforms your strings at compile-time into obfuscated data, with runtime decoding when accessed. Each macro execution uses a different random seed, ensuring that only obfuscated data exists in your binary.
In Xcode, add ObfuscateMacro as a Swift Package dependency to your project:
- File → Add Package Dependencies
- Enter:
https://github.com/p-x9/ObfuscateMacro.git
- Select version:
0.10.0
or higher
Import and use the macro:
import ObfuscateMacro
let text = #ObfuscatedString("hello")
Available methods:
- bit shift: Applies bit shifting operations
- bit XOR: Uses XOR operations
- base64: Base64 encoding with additional obfuscation
- AES: AES encryption
- random: Randomly selects from above methods
let string = #ObfuscatedString("Hello", method: .bitXOR)
// Use any method
let string = #ObfuscatedString("Hello", method: .randomAll)
// Choose from specific methods
let string = #ObfuscatedString("Hello", method: .random([.bitXOR, .AES]))
Apply multiple layers of obfuscation:
#ObfuscatedString(
"hello",
repetitions: 5
)
Use this macro for sensitive data like API keys, tokens, and internal URLs. While obfuscation adds protection, remember it's just one part of a complete security strategy.
ObfuscateMacro is released under the MIT License. See LICENSE