ObfuscateMacro

repository·main·Indexed 42 days ago

https://github.com/p-x9/obfuscatemacro

Swift macros that transform sensitive strings, such as API keys and tokens, into obfuscated data at compile-time to protect against binary analysis. Features the #ObfuscatedString macro with support for multiple obfuscation methods including .bitShift, .bitXOR, .base64, and .AES, as well as configurable repetitions for layered security.

Tokens
526
Snippets
4
Records
4
Agent score
4%

What's inside ObfuscateMacro

  1. Install ObfuscateMacro via Swift Package Manager

    main

    To use ObfuscateMacro in your Xcode project, add it as a Swift Package dependency:

    1. Go to File → Add Package Dependencies.
    2. Enter the repository URL: https://github.com/p-x9/ObfuscateMacro.git.
    3. Select version 0.10.0 or higher.
    https://github.com/p-x9/ObfuscateMacro.git
  2. Use the #ObfuscatedString macro

    main

    Import ObfuscateMacro and use the #ObfuscatedString macro to transform sensitive strings at compile-time. The macro converts the string into obfuscated data in the binary, which is then decoded at runtime when accessed. Each macro execution uses a different random seed.

    import ObfuscateMacro
    
    let text = #ObfuscatedString("hello")
  3. Apply multiple layers of obfuscation

    main

    To enhance security, you can apply multiple layers of obfuscation to a single string by using the repetitions parameter. This wraps the obfuscation process multiple times.

    #ObfuscatedString(
        "hello",
        repetitions: 5
    )
  4. Configure Obfuscation Methods for #ObfuscatedString

    main

    You can specify how the string is obfuscated using the method parameter. Available methods include:

    • .bitShift: Applies bit shifting operations.
    • .bitXOR: Uses XOR operations.
    • .base64: Base64 encoding with additional obfuscation.
    • .AES: AES encryption.
    • .randomAll: Randomly selects one of the available methods.
    • .random([methods]): Randomly selects from a specific subset of methods provided in an array.
    // Use a specific method
    let string = #ObfuscatedString("Hello", method: .bitXOR)
    
    // Use random selection from all methods
    let string = #ObfuscatedString("Hello", method: .randomAll)
    
    // Use random selection from a specific subset
    let string = #ObfuscatedString("Hello", method: .random([.bitXOR, .AES]))