/// <summary> /// Gets the key/password value from the keyChain. /// </summary> /// <returns>The key/password (or null if the password was not found in the KeyChain).</returns> /// <param name="keyName">Keyname/username.</param> public bool GetKey(string keyName, out string value) { var wantedAlias = MakeAlias(keyName, _serviceId); var aliases = _androidKeyStore.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.Contains(wantedAlias)) { var e = _androidKeyStore.GetEntry(alias, _passwordProtection) as KeyStore.SecretKeyEntry; if (e != null) { var bytes = e.SecretKey.GetEncoded(); value = System.Text.Encoding.UTF8.GetString(bytes); return(true); } } } value = null; return(false); }
public override IEnumerable <ISalesforceUser> FindAccountsForService(string serviceId) { var r = new List <SalesforceUser> (); var postfix = "-" + serviceId; var aliases = ks.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.EndsWith(postfix)) { var e = ks.GetEntry(alias, prot) as KeyStore.SecretKeyEntry; if (e != null) { var bytes = e.SecretKey.GetEncoded(); var serialized = System.Text.Encoding.UTF8.GetString(bytes); var acct = SalesforceUser.Deserialize(serialized); r.Add(acct); } } } r.Sort((a, b) => a.Username.CompareTo(b.Username)); return(r); }
IEnumerable <LoginDetails> FindAccountsForService(string serviceId) { var r = new List <LoginDetails>(); var postfix = "-" + serviceId; var aliases = _keyStore.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.EndsWith(postfix, StringComparison.Ordinal)) { var e = _keyStore.GetEntry(alias, _passwordProtection) as KeyStore.SecretKeyEntry; if (e != null) { var bytes = e.SecretKey.GetEncoded(); var serialized = Encoding.UTF8.GetString(bytes); var acct = LoginDetails.Deserialize(serialized); r.Add(acct); } } } r.Sort((a, b) => string.Compare(a.Username, b.Username, StringComparison.Ordinal)); return(r); }
public IEnumerable<Account> FindAccountsForService(string serviceId) { if (_keyStore == null) { InitializeStore(); } var accounts = new List<Account>(); string postfix = "-" + serviceId; IEnumeration aliases = _keyStore.Aliases(); while(aliases.HasMoreElements) { string alias = aliases.NextElement().ToString(); if(alias.EndsWith(postfix)) { var entry = _keyStore.GetEntry(alias, _prot) as KeyStore.SecretKeyEntry; if(entry != null) { byte[] bytes = entry.SecretKey.GetEncoded(); string serialized = Encoding.UTF8.GetString(bytes); Account account = Account.Deserialize(serialized); accounts.Add(account); } } } return accounts; }
/// <exception cref="System.IO.IOException"/> public override IList <string> GetAliases() { readLock.Lock(); try { AList <string> list = new AList <string>(); string alias = null; try { Enumeration <string> e = keyStore.Aliases(); while (e.MoveNext()) { alias = e.Current; list.AddItem(alias); } } catch (KeyStoreException e) { throw new IOException("Can't get alias " + alias + " from " + GetPathAsString(), e); } return(list); } finally { readLock.Unlock(); } }
/// <summary> /// Creates an instance of {@code PKIXParameters} that /// populates the set of most-trusted CAs from the trusted /// certificate entries contained in the specified {@code KeyStore}. /// Only keystore entries that contain trusted {@code X509Certificates} /// are considered; all other certificate types are ignored. /// </summary> /// <param name="keystore"> a {@code KeyStore} from which the set of /// most-trusted CAs will be populated </param> /// <exception cref="KeyStoreException"> if the keystore has not been initialized </exception> /// <exception cref="InvalidAlgorithmParameterException"> if the keystore does /// not contain at least one trusted certificate entry </exception> /// <exception cref="NullPointerException"> if the keystore is {@code null} </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public PKIXParameters(java.security.KeyStore keystore) throws java.security.KeyStoreException, java.security.InvalidAlgorithmParameterException public PKIXParameters(KeyStore keystore) { if (keystore == null) { throw new NullPointerException("the keystore parameter must be " + "non-null"); } Set <TrustAnchor> hashSet = new HashSet <TrustAnchor>(); IEnumerator <String> aliases = keystore.Aliases(); while (aliases.MoveNext()) { String alias = aliases.Current; if (keystore.IsCertificateEntry(alias)) { Certificate cert = keystore.GetCertificate(alias); if (cert is X509Certificate) { hashSet.Add(new TrustAnchor((X509Certificate)cert, null)); } } } TrustAnchors = hashSet; this.UnmodInitialPolicies = System.Linq.Enumerable.Empty <String>(); this.CertPathCheckers_Renamed = new List <PKIXCertPathChecker>(); this.CertStores_Renamed = new List <CertStore>(); }
public T Get <T>(string key) { var aliases = ks.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.Equals(key.Trim(), StringComparison.InvariantCulture)) { if (ks.GetEntry(alias, prot) is KeyStore.SecretKeyEntry e) { var bytes = e.SecretKey.GetEncoded(); return(JsonConvert.DeserializeObject <T>(UnicodeEncoding.UTF8.GetString(bytes))); } } } return(default(T)); }
public IEnumerable<string> FindAccountsForService(string serviceId) { var r = new List<string>(); var postfix = "-" + serviceId; var aliases = ks.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.EndsWith(postfix)) { var e = ks.GetEntry(alias, prot) as KeyStore.SecretKeyEntry; if (e != null) { var bytes = e.SecretKey.GetEncoded(); var password = System.Text.Encoding.UTF8.GetString(bytes); r.Add(password); } } } return r; }
public string GetKey(string keyName) { var wantedAlias = MakeAlias(keyName, _serviceId).ToLower(); var aliases = _androidKeyStore.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.ToLower().Contains(wantedAlias)) { var e = _androidKeyStore.GetEntry(alias, new KeyStore.PasswordProtection(_serviceId.ToCharArray())) as KeyStore.SecretKeyEntry; if (e != null) { var bytes = e.SecretKey.GetEncoded(); //return System.Text.Encoding.UTF8.GetString(bytes); return(bytes.GetString()); } } } return(""); }
public bool TryGetPassword(string username, string service, out string password) { var aliases = keystore.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.Equals(GetAlias(username, service))) { var e = keystore.GetEntry(alias, this.protection) as KeyStore.SecretKeyEntry; if (e != null) { var bytes = e.SecretKey.GetEncoded(); password = System.Text.Encoding.UTF8.GetString(bytes); return(true); } } } password = string.Empty; return(false); }
public Dictionary <string, string> FindAccountsForService(string serviceId) { Dictionary <string, string> values = null; var postfix = "-" + serviceId; var aliases = ks.Aliases(); while (aliases.HasMoreElements) { var alias = aliases.NextElement().ToString(); if (alias.EndsWith(postfix)) { var e = ks.GetEntry(alias, prot) as KeyStore.SecretKeyEntry; if (e != null) { var bytes = e.SecretKey.GetEncoded(); var serializedValues = System.Text.Encoding.UTF8.GetString(bytes); values = JsonConvert.DeserializeObject <Dictionary <string, string> >(serializedValues); } } } return(values); }
public IEnumerable <string> FindAccountsForService(string serviceId) { List <string> r = new List <string>(); string postfix = "-" + serviceId; IEnumeration aliases = _keyStore.Aliases(); while (aliases.HasMoreElements) { string alias = aliases.NextElement().ToString(); if (alias.EndsWith(postfix)) { KeyStore.SecretKeyEntry e = _keyStore.GetEntry( alias, _passProtection) as KeyStore.SecretKeyEntry; if (e != null) { byte[] bytes = e.SecretKey.GetEncoded(); string password = System.Text.Encoding.UTF8.GetString(bytes); r.Add(password); } } } return(r); }