Xcode:在最终的 iOS 应用程序中隐藏/保护资源文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11041899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode: hide / protect resource files in final iOS app?
提问by Nate
I plan to develop an app for iOS and want to use HTML5, CSS and Javascript. The final app should be implemented as a native app using Xcode and UIWebView
.
我计划为 iOS 开发一个应用程序,并希望使用 HTML5、CSS 和 Javascript。最终的应用程序应该使用 Xcode 和UIWebView
.
Can I hide or protect my html files in the final app? I have to put the files in the folder called "Supporting Files"in Xcode. Therefore, everyone can view the plain files after purchasing the app by extracting the .ipa file, right?
我可以在最终应用中隐藏或保护我的 html 文件吗?我必须将文件放在 Xcode 中名为“Supporting Files”的文件夹中。所以大家购买app后,可以通过解压.ipa文件来查看纯文件,对吧?
回答by Nate
There's many ways to protect your data, depending on how good you want the protection to be. For very minimal protection against only casual hackers, you could use a string obfuscationalgorithm to obfuscate and de-obfuscate the HTML content as NSString
s. Here's an example of doing that. I haven't used that particular code, but I'm also not really recommending obfuscationas a technique, unless the data really isn't very sensitive.
有多种方法可以保护您的数据,具体取决于您希望保护的程度。对于仅针对临时黑客的极少保护,您可以使用字符串混淆算法将 HTML 内容混淆和反混淆为NSString
s。这是一个这样做的例子。我没有使用过那个特定的代码,但我也不真正推荐混淆作为一种技术,除非数据真的不是很敏感。
The better solution is to encryptthe HTML content, although that's more work, and may involve some export control issues, depending on where you are, and where you're distributing your app.
更好的解决方案是加密HTML 内容,尽管这需要更多的工作,并且可能涉及一些出口控制问题,具体取决于您所在的位置以及您分发应用程序的位置。
For encryption, you have lots of options.
对于加密,您有很多选择。
1)Here is an open source implementation that provides a secure version of something like NSUserDefaults
. I don't see an equivalent to registerDefaults:
in that code, though, so it's possible that the firsttime your app runs, you may have to download the content from the web. But, then you could encrypt and store it in PDKeychainBindings
as a string value. On subsequent runs, you could then extract stored HTML "files"like this:
1)这是一个开源实现,它提供了诸如NSUserDefaults
. 但是,我registerDefaults:
在该代码中没有看到等效项,因此您的应用程序第一次运行时,您可能需要从 Web 下载内容。但是,您可以加密并将其存储PDKeychainBindings
为字符串值。在随后的运行中,您可以像这样提取存储的 HTML “文件”:
NSString* webPageContent =
[[PDKeychainBindings sharedKeychainBindings] valueForKey: @"index.html"];
2)Here's another open source project that provides AES encryption wrappers. You would write some non-production code before releasing your app to encrypt the HTML content into encrypted data files that would be bundle resources. When your app runs, it opens the files and decrypts them into NSString
objects which can be given to your UIWebView
via loadHTMLString: baseURL:
.
2)这是另一个提供 AES 加密包装器的开源项目。在发布应用程序之前,您将编写一些非生产代码,以将 HTML 内容加密为加密数据文件,这些文件将成为捆绑资源。当您的应用程序运行时,它会打开文件并将它们解密为NSString
可以UIWebView
通过loadHTMLString: baseURL:
.
3)Finally, here's another example of using the underlying CommonCryptoAPIs to protect bundle resources. This example uses a custom build step to automatically encrypt resources in a particular folder, which would save you some time if your protected HTML content is going to change reasonably often.
3)最后,这是使用底层CommonCryptoAPI 保护捆绑资源的另一个示例。此示例使用自定义构建步骤来自动加密特定文件夹中的资源,如果受保护的 HTML 内容经常发生合理变化,这将为您节省一些时间。
回答by pho0
You can encrypt the files and decrypt them at runtime or you can not include them in your bundle and have a compile time script that reads them and converts them into encoded data in your app that you can just load into your UIWebView with:
您可以加密文件并在运行时解密它们,或者您不能将它们包含在您的包中,并拥有一个编译时脚本来读取它们并将它们转换为您的应用程序中的编码数据,您可以使用以下命令加载到您的 UIWebView 中:
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
回答by pbx
You could create all your HTML and so on also within your code and then use UIWebView
's
您也可以在代码中创建所有 HTML 等,然后使用UIWebView
's
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
to manually load every HTML string as plain text. I advice you, however, not to do so. If somebody really wants to isolate every string from your compiled source code, this is possible for him (unless you really do demanding stuff).
手动加载每个 HTML 字符串作为纯文本。但是,我建议您不要这样做。如果有人真的想从你编译的源代码中分离出每个字符串,这对他来说是可能的(除非你真的做要求很高的事情)。
Most of the users simply don't care about what's inside the ipa file. If you can live with < 1% who inspects it, don't worry too much about this topic.
大多数用户根本不关心 ipa 文件中的内容。如果你能忍受不到 1% 的人检查它,不要太担心这个话题。
Another aspect would be possible as well (even if this is not a fantastic idea): You could point your UIWebView to a secret website only you and your app know. This is absolutely not advisable.
另一个方面也是可能的(即使这不是一个好主意):您可以将 UIWebView 指向一个只有您和您的应用程序知道的秘密网站。这是绝对不可取的。