Code Monkey home page Code Monkey logo

Comments (5)

pradeep1991singh avatar pradeep1991singh commented on May 27, 2024

@Krishna25Vrinsoft please share device details.

from cordova-plugin-secure-key-store.

parthdevmurari91 avatar parthdevmurari91 commented on May 27, 2024

/*
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.
*/

#import "SecureKeyStore.h"
#import <Cordova/CDV.h>

@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

from cordova-plugin-secure-key-store.

Krishna25Vrinsoft avatar Krishna25Vrinsoft commented on May 27, 2024

@pradeep1991singh Is this correct? If it's correct than can you please update plugin?

from cordova-plugin-secure-key-store.

pradeep1991singh avatar pradeep1991singh commented on May 27, 2024

@parthdevmurari91 It seems your solution is not using keychainWrapper, it just using NSUserDefaults which is not recommended to use for sensitive data.

from cordova-plugin-secure-key-store.

pradeep1991singh avatar pradeep1991singh commented on May 27, 2024

@Krishna25Vrinsoft
Use latest release v1.5.0 that should fix the issue. And let me know if you still facing same issue.
Thanks.

from cordova-plugin-secure-key-store.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.