From a906af9fba5bff454bdaf74868c803987f6fa0d7 Mon Sep 17 00:00:00 2001 From: Przemek Zygmunt Date: Fri, 1 Nov 2019 21:14:59 +0100 Subject: [PATCH] Set %@_encrypted to false when encryption failed --- SuplaApp.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SuplaApp.m b/SuplaApp.m index 0c445522..1a9c1811 100644 --- a/SuplaApp.m +++ b/SuplaApp.m @@ -82,9 +82,10 @@ +(SAApp*)instance { -(void) encryptData:(NSData *)data andSaveWithPrefKey:(NSString *)pref_key { @synchronized(self) { - data = [data aes128EncryptWithDeviceUniqueId]; - [[NSUserDefaults standardUserDefaults] setValue:data forKey:pref_key]; - [[NSUserDefaults standardUserDefaults] setBool:true forKey:[NSString stringWithFormat:@"%@_encrypted", pref_key]]; + NSData *encryptedData = [data aes128EncryptWithDeviceUniqueId]; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + [ud setValue:(encryptedData != nil ? encryptedData : data) forKey:pref_key]; + [ud setBool:(encryptedData != nil) forKey:[NSString stringWithFormat:@"%@_encrypted", pref_key]]; } }