Closed Krishna25Vrinsoft closed 7 years ago
@Krishna25Vrinsoft please share device details.
/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
@implementation SecureKeyStore
(void) set:(CDVInvokedUrlCommand)command
{
CDVPluginResult pluginResult = nil;
NSString key = [command.arguments objectAtIndex:0];
NSString value = [command.arguments objectAtIndex:1];
@try {
KeychainWrapper* keychain = [[KeychainWrapper alloc]init];
[keychain mySetObject:value forKey:(__bridge id)(kSecValueData)];
[keychain writeToKeychain];
//[[NSUserDefaults standardUserDefaults]setBool:true forKey:key];
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; [[NSUserDefaults standardUserDefaults]synchronize];
//NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:key]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Key saved to keychain successfully"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@catch(NSException* exception){
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Exception: saving key into keychain"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}
(void) get:(CDVInvokedUrlCommand)command { CDVPluginResult pluginResult = nil; NSString* key = [command.arguments objectAtIndex:0]; @try {
//NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:key]);
NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:key];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} @catch(NSException* exception){ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Exception: fetching key from keychain"]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } }
(void) remove:(CDVInvokedUrlCommand)command { CDVPluginResult pluginResult = nil; NSString key = (NSString)[command.arguments objectAtIndex:0]; @try { [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Key removed successfully"]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } @catch(NSException *exception) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Exception: Could not delete key from keychain"]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } }
@end
================================================================= Replace SecureKeyStore.m file with above code
@pradeep1991singh Is this correct? If it's correct than can you please update plugin?
@parthdevmurari91 It seems your solution is not using keychainWrapper
, it just using NSUserDefaults
which is not recommended to use for sensitive data.
@Krishna25Vrinsoft
Use latest release v1.5.0
that should fix the issue. And let me know if you still facing same issue.
Thanks.
In ios i have stored 2 value first store app_id (key), and value is 12345. and second value stored as pass user_pass (key) and value is 12345_pass. when i close app and again open i am getting both key with 12345_pass as value. I am try to solve but i am not getting any solution. Can you plz help us to solve out this issue.
Thanks.