/// <exception cref="System.IO.IOException"/> public override CredentialProvider.CredentialEntry GetCredentialEntry(string alias ) { readLock.Lock(); try { SecretKeySpec key = null; try { if (cache.Contains(alias)) { return(cache[alias]); } if (!keyStore.ContainsAlias(alias)) { return(null); } key = (SecretKeySpec)keyStore.GetKey(alias, password); } catch (KeyStoreException e) { throw new IOException("Can't get credential " + alias + " from " + GetPathAsString (), e); } catch (NoSuchAlgorithmException e) { throw new IOException("Can't get algorithm for credential " + alias + " from " + GetPathAsString(), e); } catch (UnrecoverableKeyException e) { throw new IOException("Can't recover credential " + alias + " from " + GetPathAsString (), e); } return(new CredentialProvider.CredentialEntry(alias, BytesToChars(key.GetEncoded( )))); } finally { readLock.Unlock(); } }
// Loads a byte[] key public void LoadKey(byte[] symKey) { var loadedKey = new SecretKeySpec(symKey, 0, symKey.Length, TRANSFORMATION); _storageHelper.StoreItem <byte[]>(_keyAlias, loadedKey.GetEncoded()); }
/// <exception cref="System.IO.IOException"/> public override KeyProvider.KeyVersion GetKeyVersion(string versionName) { readLock.Lock(); try { SecretKeySpec key = null; try { if (!keyStore.ContainsAlias(versionName)) { return(null); } key = (SecretKeySpec)keyStore.GetKey(versionName, password); } catch (KeyStoreException e) { throw new IOException("Can't get key " + versionName + " from " + path, e); } catch (NoSuchAlgorithmException e) { throw new IOException("Can't get algorithm for key " + key + " from " + path, e); } catch (UnrecoverableKeyException e) { throw new IOException("Can't recover key " + key + " from " + path, e); } return(new KeyProvider.KeyVersion(GetBaseName(versionName), versionName, key.GetEncoded ())); } finally { readLock.Unlock(); } }