Ios: 如何保護iOS束文件屬性列表,圖像,SQLite,媒體文件

Ios: 如何保護iOS束文件屬性列表,圖像,SQLite,媒體文件

我創建了Hello World示例項目,然後添加data.plist文件到資源文件夾。現在人們可以很容易得到束文件解壓縮。國際音標。有任何的方法來保護data.plist文件保存在iPhone應用程序包?

 Encryption is a decent method of scrambling the data but i don't know how to implement encription concept.

你有什麼樣的代碼?

在這裡輸入圖像描述

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
NSArray *arrData = [[NSArray alloc]initWithContentsOfFile:filePath];

NSData *datas = [NSKeyedArchiver archivedDataWithRootObject:arrData];
[datas writeToFile:filePath atomically:YES];

提取後的IPA文件

在這裡輸入圖像描述

iosiphonebundleprotection

這個問題有 2 個解答。

1 個答案

使用nskeyedarchiver要從你的字典中創建一個NSData對象(nskeyedarchiver archiveddatawithrootobject:)。然後用AES加密NSData寫,你的文件。

閱讀只是相反的過程:首先,閱讀NSData,解密它通過從上述的連接方法,然後通過解密NSData到nskeyedunarchiver(nskeyedunarchiver unarchiveobjectwithdata:)你把你的字典回來。你可以使用NSDictionary plist文件或保持你的數據安全。

實例1:

實例2:

編輯2:

NSDictionary *Your_NSDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                           @"Obj1", @"Key1",
                           @"Obj2", @"Key2", nil];//store dictionaryNSMutableData *yourData = [[NSMutableData alloc] init];NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];[archiver encodeObject:Your_NSDictionary forKey: @"key"];[archiver finishEncoding];[yourData writeToFile:@"FilePath" atomically:YES];

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"Data" 
                                                 ofType:@"plist"];NSDictionary* data = [NSDictionary dictionaryWithContentsOfFile:filePath];NSMutableDictionary * rootObject;rootObject = [NSMutableDictionary dictionary];[rootObject setValue: data forKey:@"accounts"];[NSKeyedArchiver archiveRootObject: rootObject toFile: path];

2 個答案

  1. 在MAC加密文件…在部署:

    第一:要加密的目標不添加文件
    例如:Encryption-Test.plist

    然後添加一個shell腳本相Xcode項目使用openssl加密和複製文件。
    例如:
    openssl enc -e -aes-256-cbc -pass pass:asdasd-in $PROJECT_DIR/test/Encryption-Test.plist -out $TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/Encryption-Test.enc

  2. 從GitHub添加到你的項目rncryptor源文件。這使OpenSSL加密AES解密文件很容易。(感謝Rob!)https://github.com/rncryptor/rncryptor(蘋果的ccrypt API不好直接與工作)

  3. 載入數據和解密:

例如:

@implementation TestViewController- (void)viewDidLoad{
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Encryption-Test" ofType:@"enc"];
    NSData *passEncryptedData =[[NSData alloc] initWithContentsOfFile:path];
    NSString *pass = @"asdasd";

    NSData *dataDecrypted = [RNOpenSSLDecryptor decryptData:passEncryptedData withSettings:kRNCryptorAES256Settings password:pass error:nil];
    id plist = [NSPropertyListSerialization propertyListFromData:dataDecrypted mutabilityOption:NSPropertyListImmutable format:nil errorDescription:nil];

    assert(plist);
    self.text.text = [plist description];}@end

增加了全樣本:https://github.com/daij-djan/encryptbundlefiles

如果本站有幫助到您,請不吝於給一個讚鼓勵!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章