A method to obfuscate strings in Swift.
- iOS 9.0+
- Xcode 10
You can use CocoaPods to install Obfuscator
by adding it to your Podfile
(the branch and git url won't be nessessary for long, stay tuned):
platform :ios, '9.0'
use_frameworks!
pod 'Obfuscator', :git => 'https://github.com/thexande/Obfuscator', :tag => '1.0.0'
- Download and drop
Obfuscator.swift
in your project. - Congratulations!
- Add the class to your project, init the object and call
func bytesByObfuscatingString(string: String) -> [UInt8]
final class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let obfuscator = Obfuscator()
print(obfuscator.bytesByObfuscatingString(string: "your_secret_string_here"))
}
}
- Retrieve your secret byte array from the console, and create a static container to hold it (
enum
to prevent init):
enum ObfuscatedConstants {
static let obfuscatedString: [UInt8] = [34, 17, 93, 37, 21, 28, 72, 23, 20, 22, 72, 127, 98, 123, 87, 94, 92, 83, 76, 113]
}
- Call and use (example with Google Ad SDK here).
let secret = Obfuscator().reveal(key: ObfuscatedConstants.obfuscatedString)
- Party 🎉
We would love you for the contribution to Obfuscator, check the LICENSE
file for more info.
Alexander Murphy – 🐦@thexande
Distributed under the MIT license. See LICENSE
for more information.