public bool GetKeyIv(string strDomain, string strApp, ref byte[] key, ref byte[] iv) { bool bSuccess = false; const string HTTP_PRE = "http://"; const string HTTPS_PRE = "https://"; try { if (strDomain.Length == 0 && strApp.Length == 0) { key = default_key; iv = default_iv; } else { if (!keyman_.ContainsKey(strDomain)) { //if (strDomain.IndexOf(HTTP_PRE) == 0) if (strDomain.IndexOf(HTTP_PRE) == 0 || strDomain.IndexOf(HTTPS_PRE) == 0) { CacheKeyRepo(strDomain); } else { CacheKeyRepoFromReg(strDomain); } } KeyType domainKey = new KeyType(); if (!keyman_.TryGetValue(strDomain, out domainKey)) { throw new Exception(); } KeyValueType keyv = new KeyValueType(); if (!domainKey.TryGetValue(strApp, out keyv)) { throw new Exception(); } key = keyv.Key; iv = keyv.Value; if (key == null || iv == null) { throw new Exception(); } } bSuccess = true; } catch (Exception) { } return(bSuccess); }
public static string StypeForKey(string key) { string stype; if (KeyType.TryGetValue(key, out stype)) { return(stype); } else { throw new ArgumentOutOfRangeException("key"); } }
public bool GetKeyIv(string strDomain, string strApp, ref byte[] key, ref byte[] iv) { bool bSuccess = false; const string HTTP_PRE = "http://"; const string HTTPS_PRE = "https://"; try { if (strDomain.Length == 0 && strApp.Length == 0) { key = default_key; iv = default_iv; } else { if (strDomain.IndexOf(HTTP_PRE) == 0 || strDomain.IndexOf(HTTPS_PRE) == 0) { if (!KeyRepo_.ContainsKey(strApp)) { CacheKeyRepo(strDomain); } KeyValueType keyv = new KeyValueType(); if (!KeyRepo_.TryGetValue(strApp, out keyv)) { throw new Exception(); } key = keyv.Key; iv = keyv.Value; } else { string strSubKey = SUBKEYROOT + strDomain; RegistryKey SubKeyDefault = Registry.LocalMachine.OpenSubKey(strSubKey, false); if (SubKeyDefault == null) { throw new Exception(); } RegistryKey RKey = SubKeyDefault.OpenSubKey(strApp, false); if (RKey == null) { throw new Exception(); } key = (byte[])RKey.GetValue("key"); iv = (byte[])RKey.GetValue("iv"); if (key == null || iv == null) { throw new Exception(); } } } bSuccess = true; } catch (Exception) { } return(bSuccess); }