/// <summary> /// レジストリ情報を読み込む /// </summary> private void LoadRegistry() { InternalHostsSaveTarget = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrInternalHostsTargetRegistryName); ExternalHostsSaveTarget = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrExternalHostsTargetRegistryName); NetworkAuthenticationUsername = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationUsernameName); int value = 0; if (RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsApplyInExternalHostsRegistryName, out value) == true) { IsApplyInExternalHosts = (value == 0) ? false : true; } if (RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsUpdateInternalHostsRegistryName, out value) == true) { IsUpdateInternalHosts = (value == 0) ? false : true; } if (RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsNetworkAuthenticationName, out value) == true) { IsNetworkAuthentication = (value == 0) ? false : true; } internalHostsPathTextBox.Text = InternalHostsSaveTarget; externalHostsPathTextBox.Text = ExternalHostsSaveTarget; networkAuthenticationUsernameTextBox.Text = NetworkAuthenticationUsername; networkAuthenticationPasswordPasswordBox.Password = CryptUtility.DecryptString(RegistryUtility.RGBRegistryReadBinaryValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationPasswordName)); internalHostsPathCheckBox.IsChecked = IsUpdateInternalHosts; externalHostsPathCheckBox.IsChecked = IsApplyInExternalHosts; networkAuthenticationCheckBox.IsChecked = IsNetworkAuthentication; }
/// <summary> /// レジストリ情報を読み込む /// </summary> private void LoadRegistry() { string strInternalHostsSaveTarget = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrInternalHostsTargetRegistryName); string strExternalHostsSaveTarget = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrExternalHostsTargetRegistryName); internalHostsSaveTargetCollection = strInternalHostsSaveTarget.Split(new char[] { ';' }).Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)); externalHostsSaveTargetCollection = strExternalHostsSaveTarget.Split(new char[] { ';' }).Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)); NetworkAuthenticationUsername = RegistryUtility.StrRegistryReadValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationUsernameName); NetworkAuthenticationPassword = CryptUtility.DecryptString(RegistryUtility.RGBRegistryReadBinaryValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationPasswordName)); int value = 0; if (RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsApplyInExternalHostsRegistryName, out value) == true) { IsApplyInExternalHosts = (value == 0) ? false : true; } if (RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsUpdateInternalHostsRegistryName, out value) == true) { IsUpdateInternalHosts = (value == 0) ? false : true; } if (RegistryUtility.FRegistryReadDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsNetworkAuthenticationName, out value) == true) { IsNetworkAuthentication = (value == 0) ? false : true; } }
public ApiResult Post(PostModel post) { if (!ModelState.IsValid) { var errorList = ModelState.Where(x => x.Value.Errors.Count > 0) .ToDictionary(x => x.Key, x => x.Value.Errors.Select(e => e.ErrorMessage)); return(apiResult(0, errorList)); } try { var formData = JsonConvert.DeserializeObject <Dictionary <string, string> >(post.ApiRequest); // 需加入簽章 if (post.IsNeedSignature) { var tmp = formData.OrderBy(x => x.Key) .Select(x => string.Format("{0}={1}", x.Key, x.Value)); string signature = CryptUtility.HMACSHA1(post.ApiKey, string.Join("&", tmp)); formData.Add("signature", signature); } // 財政部測試環境 if (post.IsTestMode) { post.ApiUrl = post.ApiUrl.Replace("//www.", "//wwwtest.") .Replace("//api.", "//wwwtest."); } var query = formData.Select(x => string.Format("{0}={1}", x.Key, HttpUtility.UrlEncode(x.Value))); string url = string.Format("{0}?{1}", post.ApiUrl.TrimEnd('?'), string.Join("&", query)); if (post.IsClientMode) { return(apiResult(100, url)); } else { string result = null; using (HttpClient hc = new HttpClient()) { // 30 秒 Time Out hc.Timeout = TimeSpan.FromSeconds(30); result = hc.GetStringAsync(url).Result; } return(apiResult(1, new { url, result })); } } catch (Exception ex) { return(apiResult(-1, ex.Message)); } }
private String CreateSignature(String privateKey, String apiKey, String uri, String dateStr, String requestData) { String content = apiKey + uri.Split('?')[0] + dateStr + requestData; Logger.Log("-" + content + "-"); CryptUtility cu = new CryptUtility(); return(cu.createSignature(privateKey, content)); }
private static string CreateSignature(string privateKey, string apiKey, string uri, string dateStr, string requestData) { var content = apiKey + uri + dateStr + requestData; Logger.Log("-" + content + "-"); var cu = new CryptUtility(); return(cu.CreateSignature(privateKey, content)); }
public PrivateKey GenerateKeyPair(String description) { CryptUtility cu = new CryptUtility(); Keypair keyPair = cu.GenerateKeyPair(KEY_EMAIL); String publicKeyId = UploadPublicKey(keyPair.PublicKey, description); PrivateKey privateKey = new PrivateKey(); privateKey.ArmoredKey = keyPair.PrivateKey; privateKey.PublicKeyID = publicKeyId; return(privateKey); }
public void Save() { // Serialize and encrypt byte[] pack = Encoding.UTF8.GetBytes(JsonUtility.ToJson(Model));; byte[] iv = null; byte[] data = null; CryptUtility.EncryptAESWithCBC(pack, Encoding.UTF8.GetBytes(EncryptKey), EncryptKeyCount, out iv, out data); // Save FileUtility.Save(FilePath, writer => { writer.Write(iv.Length); writer.Write(iv); writer.Write(data.Length); writer.Write(data); }); }
public void Load() { // Load byte[] iv = null; byte[] data = null; FileUtility.Load(FilePath, reader => { int length = reader.ReadInt32(); iv = reader.ReadBytes(length); length = reader.ReadInt32(); data = reader.ReadBytes(length); }); // Decrypt and Deserialize byte[] pack = null; CryptUtility.DecryptAESWithCBC(data, Encoding.UTF8.GetBytes(EncryptKey), iv, out pack); _model = JsonUtility.FromJson <T>(Encoding.UTF8.GetString(pack)); }
public String GetKeycode(String packageId, PrivateKey privateKey) { String publicKeyId = privateKey.PublicKeyID; String privateKeyStr = privateKey.ArmoredKey; Endpoint p = ConnectionStrings.Endpoints["getKeycode"].Clone(); p.Path = p.Path.Replace("{publicKeyId}", publicKeyId); p.Path = p.Path.Replace("{packageId}", packageId); StandardResponse response = connection.Send <StandardResponse>(p); if (response.Response != APIResponse.SUCCESS) { throw new GettingKeycodeFailedException("Failed to get keycode: " + response.Message); } String encryptedKeycode = response.Message; CryptUtility cu = new CryptUtility(); String keycode = cu.DecryptKeycode(privateKeyStr, encryptedKeycode); return(keycode); }
/// <summary> /// 現在の設定をレジストリに保存する /// </summary> private void SaveRegistry() { // ExternalHostsTarget RegistryUtility.FRegistrySetValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrExternalHostsTargetRegistryName, ExternalHostsSaveTarget); // InternalHostsTarget RegistryUtility.FRegistrySetValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrInternalHostsTargetRegistryName, InternalHostsSaveTarget); // ApplyInExternalHosts (Enabled) RegistryUtility.FRegistrySetDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsApplyInExternalHostsRegistryName, (IsApplyInExternalHosts) ? (uint)1 : (uint)0); // UpdateInternalHosts (Enabled) RegistryUtility.FRegistrySetDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsUpdateInternalHostsRegistryName, (IsUpdateInternalHosts) ? (uint)1 : (uint)0); // NetworkAuthentication (Disabled) RegistryUtility.FRegistrySetDwordValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrIsNetworkAuthenticationName, (IsNetworkAuthentication) ? (uint)1 : (uint)0); // NetworkAuthenticationUsername (Empty) RegistryUtility.FRegistrySetValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationUsernameName, NetworkAuthenticationUsername); // NetworkAuthenticationPassword (Empty) RegistryUtility.FRegistrySetBinaryValue(Microsoft.Win32.RegistryHive.LocalMachine, LocalResources.m_gstrAutoHostsUpdateServiceRegistryPath, LocalResources.m_gstrNetworkAuthenticationPasswordName, CryptUtility.EncryptString(NetworkAuthenticationPassword)); }