Cipher CreateCipher(bool retry = true)
            {
                IKey   key    = GetKey();
                Cipher cipher = Cipher.GetInstance(TRANSFORMATION);

                try
                {
                    if (_iv.Length > 0)
                    {
                        cipher.Init(_mode, key, new IvParameterSpec(_iv));
                    }
                    else
                    {
                        cipher.Init(_mode, key);
                    }
                }
                catch (KeyPermanentlyInvalidatedException e)
                {
                    _keystore.DeleteEntry(KEY_NAME);
                    if (retry)
                    {
                        CreateCipher(false);
                    }
                    else
                    {
                        throw new System.Exception("Could not create the cipher for fingerprint authentication.", e);
                    }
                }
                return(cipher);
            }
Esempio n. 2
0
        /// <summary>
        ///     Creates the cipher.
        /// </summary>
        /// <returns>The cipher.</returns>
        /// <param name="retry">If set to <c>true</c>, recreate the key and try again.</param>
        Cipher CreateCipher(CipherMode cipherMode, byte[] iv = null, bool retry = true)
        {
            IKey   key    = GetKey();
            Cipher cipher = Cipher.GetInstance(TRANSFORMATION);

            if (cipherMode == CipherMode.EncryptMode)
            {
                try
                {
                    cipher.Init(cipherMode, key);
                }
                catch (KeyPermanentlyInvalidatedException e)
                {
                    Log.Debug(TAG, "The key was invalidated, creating a new key.");
                    _keystore.DeleteEntry(KEY_NAME);
                    if (retry)
                    {
                        CreateCipher(cipherMode, null, false);
                    }
                    else
                    {
                        throw new Exception("Could not create the cipher for fingerprint authentication.", e);
                    }
                }
            }
            else if (cipherMode == CipherMode.DecryptMode)
            {
                cipher.Init(cipherMode, key, new IvParameterSpec(iv));
            }

            return(cipher);
        }
        /// <summary>
        ///     Creates the cipher.
        /// </summary>
        /// <returns>The cipher.</returns>
        /// <param name="retry">If set to <c>true</c>, recreate the key and try again.</param>
        Cipher CreateCipher(bool retry = true)
        {
            IKey   key    = GetKey();
            Cipher cipher = Cipher.GetInstance(Transformation);

            try
            {
                cipher.Init(CipherMode.EncryptMode, key);
            }
            catch (KeyPermanentlyInvalidatedException e)
            {
                Logger.Debug("[CryptoHelper] The key was invalidated, creating a new key.");
                _keystore.DeleteEntry(_keyName);
                if (retry)
                {
                    CreateCipher(false);
                }
                else
                {
                    throw new Exception("Could not create the cipher for fingerprint authentication.", e);
                }
            }

            return(cipher);
        }
Esempio n. 4
0
        public void Delete(string serviceId)
        {
            string alias = MakeAlias(serviceId);

            _keyStore.DeleteEntry(alias);
            Save();
        }
Esempio n. 5
0
        void Delete(LoginDetails account, string serviceId)
        {
            var alias = MakeAlias(account, serviceId);

            _keyStore.DeleteEntry(alias);
            Save();
        }
Esempio n. 6
0
        public Cipher CreateCipher(CipherMode mode, bool retry = true)
        {
            IKey   key    = GetKey();
            Cipher cipher = Cipher.GetInstance(TRANSFORMATION);

            try
            {
                if (mode == CipherMode.EncryptMode)
                {
                    cipher.Init(mode, key);
                    (new ConfigAndroid()).EncryptedPasswordIV = cipher.GetIV();
                }
                else if (mode == CipherMode.DecryptMode)
                {
                    byte[] IV = (new ConfigAndroid()).EncryptedPasswordIV;
                    cipher.Init(mode, key, new IvParameterSpec(IV));
                }
            }
            catch (KeyPermanentlyInvalidatedException e)
            {
                _keystore.DeleteEntry(KEY_NAME);
                if (retry)
                {
                    CreateCipher(mode, false);
                }
                else
                {
                    throw new Exception("Could not create the cipher for fingerprint authentication.", e);
                }
            }
            return(cipher);
        }
        public override void Delete(Account account, string serviceId)
        {
            var alias = MakeAlias(account, serviceId);

            ks.DeleteEntry(alias);
            Save();
        }
 /// <exception cref="System.IO.IOException"/>
 public override void DeleteCredentialEntry(string name)
 {
     writeLock.Lock();
     try
     {
         try
         {
             if (keyStore.ContainsAlias(name))
             {
                 keyStore.DeleteEntry(name);
             }
             else
             {
                 throw new IOException("Credential " + name + " does not exist in " + this);
             }
         }
         catch (KeyStoreException e)
         {
             throw new IOException("Problem removing " + name + " from " + this, e);
         }
         Collections.Remove(cache, name);
         changed = true;
     }
     finally
     {
         writeLock.Unlock();
     }
 }
     public void Delete(string serviceId)
     {
         var alias = MakeAlias(serviceId);
 
         ks.DeleteEntry(alias);
         Save();
     }
Esempio n. 10
0
        private BiometricPrompt.CryptoObject BuildSymmetricCryptoObject(string keyName, string cipherName, CipherMode mode, byte[] iv = null)
        {
            if (this.Log().IsEnabled(LogLevel.Debug))
            {
                this.Log().Debug($"Building a symmetric crypto object (key name: '{keyName}', mode: '{mode}').");
            }

            var cipher = Cipher.GetInstance(cipherName);

            if (_keyStore.IsKeyEntry(keyName))
            {
                if (mode == CipherMode.EncryptMode)
                {
                    _keyStore.DeleteEntry(keyName);
                }
                else if (mode == CipherMode.DecryptMode)
                {
                    try
                    {
                        cipher.Init(mode, _keyStore.GetKey(keyName, null), new IvParameterSpec(iv));

                        return(new BiometricPrompt.CryptoObject(cipher));
                    }
                    catch (KeyPermanentlyInvalidatedException)
                    {
                        _keyStore.DeleteEntry(keyName);

                        throw;
                    }
                }
            }
            else if (mode == CipherMode.DecryptMode)
            {
                throw new ArgumentException("Key not found.");
            }

            GenerateSymmetricKey(keyName);

            cipher.Init(mode, _keyStore.GetKey(keyName, null));

            if (this.Log().IsEnabled(LogLevel.Information))
            {
                this.Log().Info($"Return the symmetric crypto object (key name: '{keyName}', mode: '{mode}').");
            }

            return(new BiometricPrompt.CryptoObject(cipher));
        }
 public void Delete(string key)
 {
     if (keyStore.ContainsAlias(key))
     {
         keyStore.DeleteEntry(key);
         Save();
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Deletes a key (or a password) from the KeyChain.
        /// </summary>
        /// <returns><c>true</c>, if key was deleted, <c>false</c> otherwise.</returns>
        /// <param name="keyName">Key name (or username).</param>
        public bool DeleteKey(string keyName)
        {
            var alias = MakeAlias(keyName, _serviceId);

            _androidKeyStore.DeleteEntry(alias);
            Save();
            return(true);
        }
        public void DeleteKey(string keyName)
        {
            var alias = MakeAlias(keyName, _serviceId);

            _androidKeyStore.DeleteEntry(alias);

            Save();
        }
Esempio n. 14
0
 public bool DeleteKey()
 {
     if (!_androidKeyStore.ContainsAlias(_keyAlias))
     {
         return(false);
     }
     _androidKeyStore.DeleteEntry(_keyAlias);
     return(true);
 }
Esempio n. 15
0
        public void Delete(Account account, string serviceId)
        {
            if(_keyStore == null)
            {
                InitializeStore();
            }

            string alias = $"{account.Username}-{serviceId}";
            _keyStore.DeleteEntry(alias);
            SaveCurrent();
        }
Esempio n. 16
0
        private App.Models.SymmetricCryptoKey GetAesKey(bool v1 = false)
        {
            try
            {
                var aesKey = v1 ? AesKeyV1 : AesKey;
                if (!_settings.Contains(aesKey))
                {
                    return(null);
                }

                var encKey = _settings.GetValueOrDefault(aesKey, null);
                if (string.IsNullOrWhiteSpace(encKey))
                {
                    return(null);
                }

                if (_oldAndroid || v1)
                {
                    var encKeyBytes = Convert.FromBase64String(encKey);
                    var key         = RsaDecrypt(encKeyBytes, v1);
                    return(new App.Models.SymmetricCryptoKey(key));
                }
                else
                {
                    var parts = encKey.Split('|');
                    if (parts.Length < 2)
                    {
                        return(null);
                    }

                    var ivBytes     = Convert.FromBase64String(parts[0]);
                    var encKeyBytes = Convert.FromBase64String(parts[1]);
                    var key         = AesDecrypt(ivBytes, encKeyBytes);
                    return(new App.Models.SymmetricCryptoKey(key));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot get AesKey.");
                _keyStore.DeleteEntry(KeyAlias);
                _settings.Remove(AesKey);
                if (!v1)
                {
                    //Utilities.SendCrashEmail(e);
                    //Utilities.SaveCrashFile(e);
                }
                return(null);
            }
        }
        private Cipher CreateCipher()
        {
            IKey   key    = GetKey();
            Cipher cipher = Cipher.GetInstance(TRANSFORMATION);

            try
            {
                cipher.Init(CipherMode.EncryptMode | CipherMode.DecryptMode, key);
            }
            catch (KeyPermanentlyInvalidatedException)
            {
                _keystore.DeleteEntry(KEY_NAME);
                throw new FingerprintStoreInvalidatedException();
            }
            return(cipher);
        }
Esempio n. 18
0
        Cipher CreateCipher(bool retry = true)
        {
            IKey   key    = GetKey();
            Cipher cipher = Cipher.GetInstance(TRANSFORMATION);

            try
            {
                cipher.Init(CipherMode.EncryptMode, key);
            } catch (KeyPermanentlyInvalidatedException e)
            {
                _keystore.DeleteEntry(KEY_NAME);
                if (retry)
                {
                    CreateCipher(false);
                }
                else
                {
                    throw new Exception("Could not create the cipher for fingerprint authentication.", e);
                }
            }
            return(cipher);
        }
 /// <summary>
 /// Deletes all saved data.
 /// If there is a master key used for storage, it is deleted too
 /// </summary>
 public void WipeStorage()
 {
     _keyStore.DeleteEntry(_secureStoredKeyAlias);
     CrossSettings.Current.Remove(_settingStoredKeyAlias);
 }
Esempio n. 20
0
 public void Delete(string key)
 {
     ks.DeleteEntry(key.Trim());
     Save();
 }
 public void RemoveKey()
 {
     _keyStore.DeleteEntry(_alias);
 }
        public override void Delete(ISalesforceUser account, string serviceId)
        {
            var alias = MakeAlias(account, serviceId);

            ks.DeleteEntry(alias);
        }