Last active
July 20, 2017 18:22
-
-
Save paulocoutinhox/6a620948871724cf637519dbfd833c6a to your computer and use it in GitHub Desktop.
Decryptor em Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getDecryptedData() -> String? { | |
| do { | |
| if let productDirectory = product.getDownloadDirectoryPath() { | |
| let directory = productDirectory | |
| .appendingPathComponent("coisas-que-so-eu-sei-offline") | |
| .appendingPathComponent("coisas-que-so-eu-sei") | |
| .appendingPathComponent("json_files") | |
| Logger.i("Obtendo arquivos do reader em: %@", directory.path) | |
| let cipherFile = directory.appendingPathComponent("structure.js") | |
| let cipherText = try String(contentsOf: cipherFile, encoding: String.Encoding.utf8) | |
| let aesKey = Util.base64ToByteArray(base64String: "6LMmbmbL4EKvi55WJFxZHW5FOH25/RGbuD3Vx8MEYGU=\n")! | |
| let aesIV = Util.base64ToByteArray(base64String: "N9mT3Z5DzqghlBVBC0YsTg==\n")! | |
| let aes = try AES(key: aesKey, iv: aesIV) | |
| let decryptedText = try cipherText.decryptBase64ToString(cipher: aes) | |
| return decryptedText | |
| } | |
| } | |
| catch let error { | |
| Logger.e("Erro ao preparar arquivos: %@", error.localizedDescription) | |
| } | |
| return nil | |
| } | |
| static func base64ToByteArray(base64String: String) -> [UInt8]? { | |
| if let nsdata = NSData(base64Encoded: base64String, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters) { | |
| var bytes = [UInt8](repeating: 0, count: nsdata.length) | |
| nsdata.getBytes(&bytes,length: nsdata.length) | |
| return bytes | |
| } | |
| return nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment