static void Save_Internal() { var v_storageKey = GenerateStorageKey(); if (s_instance != null && s_instance._storageKV.Count > 0) { s_instance.m_values.Clear(); s_instance.m_keys.Clear(); //Serialize Original Keys with Encrypted Values foreach (var v_key in s_instance._originalKeys) { var v_internalStorageKey = GenerateInternalStorateKey(v_key); if (s_instance._storageKV.ContainsKey(v_internalStorageKey)) { s_instance.m_keys.Add(v_key); var v_value = s_instance._storageKV[v_internalStorageKey]; s_instance.m_values.Add(v_value); } } var v_storageIv = GenerateIV(v_storageKey); var v_encryptedStorage = Encrypt(v_storageIv, null, SerializationUtils.ToJson(s_instance)); PlayerPrefs.SetString(v_storageKey, v_encryptedStorage); //Terminate the instance apply to player prefs s_instance = null; } else if (PlayerPrefs.HasKey(v_storageKey)) { PlayerPrefs.DeleteKey(v_storageKey); } PlayerPrefs.Save(); }
public static bool Save <T>(string p_key, T p_credentialData) { var v_sucess = CredentialsKeyStore.SetCredential <T>(p_key, p_credentialData); if (v_sucess) { CredentialsKeyStore.Save(); } return(v_sucess); }
static void Load_Internal() { var v_storageKey = GenerateStorageKey(); if (PlayerPrefs.HasKey(v_storageKey)) { var v_encryptedValue = PlayerPrefs.GetString(v_storageKey); var v_storageIv = GenerateIV(v_storageKey); if (!string.IsNullOrEmpty(v_encryptedValue)) { var v_json = Decrypt(v_storageIv, null, v_encryptedValue); if (!string.IsNullOrEmpty(v_json)) { try { s_instance = SerializationUtils.FromJson <CredentialsKeyStore>(v_json); //Fill values in Dict if (s_instance.m_keys != null) { for (int i = 0; i < s_instance.m_keys.Count; i++) { var v_key = s_instance.m_keys[i]; if (!string.IsNullOrEmpty(v_key)) { //Save as internal storage key in dictionary var v_internalStorageKey = GenerateInternalStorateKey(v_key); if (!string.IsNullOrEmpty(v_internalStorageKey)) { s_instance._originalKeys.Add(v_key); var v_value = s_instance.m_values != null && s_instance.m_values.Count > i ? s_instance.m_values[i] : null; s_instance._storageKV[v_internalStorageKey] = v_value; } } } s_instance.m_keys.Clear(); s_instance.m_values.Clear(); } } catch (Exception e) { Debug.Log(e.StackTrace); } } } } if (s_instance == null) { s_instance = new CredentialsKeyStore(); } }
protected void RetrieveStoredKey_Instance(string p_storedKey, System.Action <AuthResponse> callback, string p_dialogTitle = null, string p_dialogSubtitle = null, string p_cancelText = null) { if (CredentialsKeyStore.HasKey(p_storedKey)) { //Create and register delegates if (callback != null) { System.Action v_delegateUnregister = null; System.Action <AuthResponse> v_delegateCallback = (result) => { v_delegateUnregister(); if (callback != null) { callback(result); } }; v_delegateUnregister = () => { OnAuthFailed -= v_delegateCallback; OnAuthSucess -= v_delegateCallback; }; OnAuthFailed += v_delegateCallback; OnAuthSucess += v_delegateCallback; } if (IsBiometricHardwareAvailable_Native()) { _processingStoredKey = p_storedKey; StartFingerprint_Native(p_dialogTitle, p_dialogSubtitle, p_cancelText); if (OnAuthStarted != null) { OnAuthStarted(); } } //Failed to retrieve fingerprint (permission failed, or fingerprint sensor not available) else { OnAuthenticationBridgeDidFinish(FINGERPRINT_NOT_AVAILABLE); } } else { OnAuthenticationBridgeDidFinish(INVALID_CREDENTIALS); } }
//this is the true return function (after all chances over, or sucess == true) protected internal void OnAuthenticationBridgeDidFinish(string p_error) { _remainingFailChances = 0; bool v_success = string.IsNullOrEmpty(p_error); if (v_success && !CredentialsKeyStore.HasKey(_processingStoredKey)) { p_error = INVALID_CREDENTIALS; v_success = false; } if (v_success) { var v_credentialValueStr = CredentialsKeyStore.GetString(_processingStoredKey); //Sucess if (!string.IsNullOrEmpty(v_credentialValueStr)) { if (OnAuthSucess != null) { OnAuthSucess(new AuthResponse(_processingStoredKey, v_credentialValueStr, null)); } } //Failed to retrieve credentials else { p_error = INVALID_CREDENTIALS; v_success = false; } } if (!v_success) { Debug.Log("Auth Error: " + p_error); if (OnAuthFailed != null) { OnAuthFailed(new AuthResponse(_processingStoredKey, null, p_error)); } } _processingStoredKey = null; }
public static void DeleteAll() { CredentialsKeyStore.DeleteAll(); }
public static void Delete(string p_key) { CredentialsKeyStore.DeleteKey(p_key); CredentialsKeyStore.Save(); }
public static bool HasKey(string p_key) { return(CredentialsKeyStore.HasKey(p_key)); }