private static CreateDatakeyResponse CreateDataKey(KmsClient kmsClient) { try { var request = new CreateDatakeyRequest { VersionId = "v1.0", Body = new CreateDatakeyRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), DatakeyLength = "512" } }; var resp = kmsClient.CreateDatakey(request); Console.WriteLine(resp.ToString()); return(resp); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } return(null); }
/// <summary> /// 创建数据密钥 /// </summary> public async Task <CreateDatakeyResponse> CreateDatakeyAsync(CreateDatakeyRequest createDatakeyRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); urlParam.Add("version_id", createDatakeyRequest.VersionId.ToString()); string urlPath = HttpUtils.AddUrlPath("/{version_id}/{project_id}/kms/create-datakey", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", createDatakeyRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <CreateDatakeyResponse>(response)); }