private static void ListGrant(KmsClient kmsClient) { try { var request = new ListGrantsRequest { VersionId = "v1.0", Body = new ListGrantsRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2") } }; var resp = kmsClient.ListGrants(request); Console.WriteLine(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); } }
private static void GetProjectTags(KmsClient kmsClient) { try { var req = new ListKmsTagsRequest { VersionId = "v1.0" }; var resp = kmsClient.ListKmsTags(req); foreach (var tag in resp.Tags) { Console.Write("key: " + tag.Key + " "); Console.Write("value: "); foreach (var value in tag.Values) { Console.Write(" " + value + " "); } Console.WriteLine(); } } 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); } }
private static void RetireGrant(KmsClient kmsClient) { try { var request = new CancelSelfGrantRequest { VersionId = "v1.0", Body = new RevokeGrantRequestBody { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), GrantId = CreateGrant(kmsClient) } }; var resp = kmsClient.CancelSelfGrant(request); Console.WriteLine(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); } }
private static void DeleteTag(KmsClient kmsClient) { try { var req = new DeleteTagRequest { VersionId = "v1.0", KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), Key = "key" }; var resp = kmsClient.DeleteTag(req); Console.WriteLine(resp.HttpStatusCode); } 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); } }
private static void DeleteKeyMaterial(KmsClient kmsClient, string keyId) { try { var req = new DeleteImportedKeyMaterialRequest { VersionId = "v1.0", Body = new OperateKeyRequestBody { KeyId = keyId } }; var resp = kmsClient.DeleteImportedKeyMaterial(req); Console.WriteLine(resp.GetHttpStatusCode()); } 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); } }
private static void CreateTag(KmsClient kmsClient) { var tagItem = new TagItem(); tagItem.Key = "key"; tagItem.Value = "value"; try { var req = new CreateKmsTagRequest { VersionId = "v1.0", KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), Body = new CreateKmsTagRequestBody { Tag = tagItem } }; var resp = kmsClient.CreateKmsTag(req); Console.WriteLine(resp.HttpStatusCode); } 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); } }
private static void GetKeyTag(KmsClient kmsClient) { try { var req = new ShowKmsTagsRequest { VersionId = "v1.0", KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2") }; var resp = kmsClient.ShowKmsTags(req); Console.WriteLine(resp.ToString()); } 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); } }
private static void CreateKey(KmsClient kmsClient) { var req = new CreateKeyRequest { VersionId = "v1.0", Body = new CreateKeyRequestBody() { KeyAlias = "0000" } }; try { var resp = kmsClient.CreateKey(req); Console.WriteLine(resp.ToString()); } 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); } }
private static void DecryptData(KmsClient kmsClient) { try { var request = new DecryptDataRequest { VersionId = "v1.0", Body = new DecryptDataRequestBody() { CipherText = EncryptData(kmsClient).CipherText } }; var resp = kmsClient.DecryptData(request); Console.WriteLine(resp.ToString()); } 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); } }
private static void EnableKeyRotation(KmsClient kmsClient) { try { if (GetKeyRotationStatus(kmsClient).KeyRotationEnabled.GetValueOrDefault()) { DisableKeyRotation(kmsClient); } var request = new EnableKeyRotationRequest { VersionId = "v1.0", Body = new OperateKeyRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2") } }; var resp = kmsClient.EnableKeyRotation(request); Console.WriteLine(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); } }
private static void GenRandom(KmsClient kmsClient) { var request = new CreateRandomRequest { VersionId = "v1.0", Body = new GenRandomRequestBody() { RandomDataLength = "512" } }; try { var resp = kmsClient.CreateRandom(request); Console.WriteLine(resp.ToString()); } 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); } }
private static void CreateDataKeyWithoutPlaintext(KmsClient kmsClient) { try { var request = new CreateDatakeyWithoutPlaintextRequest { VersionId = "v1.0", Body = new CreateDatakeyRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), DatakeyLength = "512" } }; var resp = kmsClient.CreateDatakeyWithoutPlaintext(request); Console.WriteLine(resp.ToString()); } 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); } }
private static void DeleteKey(KmsClient kmsClient) { try { var req = new DeleteKeyRequest { VersionId = "v1.0", Body = new ScheduleKeyDeletionRequestBody { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), PendingDays = "365" } }; var resp = kmsClient.DeleteKey(req); Console.WriteLine(resp.ToString()); } 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); } }
private static void EncryptDataKey(KmsClient kmsClient) { try { var data = DecryptDataKey(kmsClient); var plainText = data.DataKey + data.DatakeyDgst; var request = new EncryptDatakeyRequest { VersionId = "v1.0", Body = new EncryptDatakeyRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), DatakeyPlainLength = "64", PlainText = plainText } }; var resp = kmsClient.EncryptDatakey(request); Console.WriteLine(resp.ToString()); } 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); } }
private static void GetVersion(KmsClient kmsClient) { try { var req = new ShowVersionRequest { VersionId = "v1.0" }; var resp = kmsClient.ShowVersion(req); Console.WriteLine(resp.ToString()); } 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); } }
private static void ImportKeyMaterial(KmsClient kmsClient, string keyId) { var importToken = "AACIBjIzZTI1Mzk2LTQwMGItNDA0Mi1hNmYzLTM2YmRiYTIwYmU2ZQAA4Q9F+dVOE6dapktmmmZGhNeqQYj7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8="; var encryptedKeyMaterial = "C6aqYsmfRjLGGkCxE9Wzm9rqc2yuOJZI4um5jSYHLebEzNyvXfX0Uk8Jkw5806S2IaW+n2gv6+K6hVqKDAzol5P8ycZRv/zvpvzgRjgbNMoFZz7xodsOXAHR+o5qZoeszoSYbLwWUt64/DSg68KxrgSYRO2H/03ROx+yCYKypJmsBlHWAg6AnnQQoxn6Ez5kDqTJKBNfMah8JibwcGU9+BuTr2WfWslqEa5LoMjc9HKPpTR1qh97e92VeGZ7JJ6ofODskNzJwj1jg1GTaBUqp6rBQmXaITmphcQt0/4aoxEqlgrgYLHX/Sxo3xwpRqZMFR7c4hFqM4lzSi1C21uxyQ=="; try { var req = new ImportKeyMaterialRequest { VersionId = "v1.0", Body = new ImportKeyMaterialRequestBody { KeyId = keyId, ImportToken = importToken, EncryptedKeyMaterial = encryptedKeyMaterial } }; var resp = kmsClient.ImportKeyMaterial(req); Console.WriteLine(resp.HttpStatusCode); } 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); } }
private static CreateParametersForImportResponse GetParametersForImport(KmsClient kmsClient, string keyId) { try { var req = new CreateParametersForImportRequest { VersionId = "v1.0", Body = new GetParametersForImportRequestBody { KeyId = keyId, WrappingAlgorithm = GetParametersForImportRequestBody.WrappingAlgorithmEnum.RSAES_OAEP_SHA_1 } }; var resp = kmsClient.CreateParametersForImport(req); 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); }
static void Main1(string[] args) { const string ak = "{your ak string}"; const string sk = "{your sk string}"; const string endpoint = "{your endpoint string}"; const string projectId = "{your projectID string}"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk, projectId); var kmsClient = KmsClient.NewBuilder() .WithCredential(auth) .WithEndPoint(endpoint) .WithHttpConfig(config).Build(); CreateKey(kmsClient); DeleteKey(kmsClient); CancelKeyDeletion(kmsClient); EnableKey(kmsClient); DisableKey(kmsClient); EnableKey(kmsClient); UpdateKeyAlias(kmsClient); UpdateKeyDescription(kmsClient); }
static void Main1(string[] args) { const string ak = "{your ak string}"; const string sk = "{your sk string}"; const string endpoint = "{your endpoint string}"; const string projectId = "{your projectID string}"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk, projectId); var kmsClient = KmsClient.NewBuilder() .WithCredential(auth) .WithEndPoint(endpoint) .WithHttpConfig(config).Build(); CreateTag(kmsClient); DeleteTag(kmsClient); BatchCreateTags(kmsClient); BatchDeleteTags(kmsClient); GetKeyTag(kmsClient); GetProjectTags(kmsClient); GetResourceInstance(kmsClient); }
private static EncryptDataResponse EncryptData(KmsClient kmsClient) { try { var request = new EncryptDataRequest { VersionId = "v1.0", Body = new EncryptDataRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), PlainText = "hello world" } }; var resp = kmsClient.EncryptData(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); }
private static void EnableKey(KmsClient kmsClient) { try { var req = new EnableKeyRequest { VersionId = "v1.0", Body = new OperateKeyRequestBody { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "3") } }; var resp = kmsClient.EnableKey(req); Console.WriteLine(resp.ToString()); } 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); } }
private static ShowKeyRotationStatusResponse GetKeyRotationStatus(KmsClient kmsClient) { try { var request = new ShowKeyRotationStatusRequest { VersionId = "v1.0", Body = new OperateKeyRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2") } }; var resp = kmsClient.ShowKeyRotationStatus(request); Console.WriteLine(resp); 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); }
private static void UpdateKeyDescription(KmsClient kmsClient) { try { var req = new UpdateKeyDescriptionRequest { VersionId = "v1.0", Body = new UpdateKeyDescriptionRequestBody { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), KeyDescription = "0000" } }; var resp = kmsClient.UpdateKeyDescription(req); Console.WriteLine(resp.ToString()); } 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); } }
public static string GetKeyByKeyStatus(KmsClient kmsClient, string status) { var request = new ListKeysRequest { VersionId = "v1.0", Body = new ListKeysRequestBody { KeyState = status } }; try { var resp = kmsClient.ListKeys(request); if (resp.Keys.Count != 0) { return(resp.Keys[0]); } var req = new CreateKeyRequest { VersionId = "v1.0", Body = new CreateKeyRequestBody() { KeyAlias = "0000" } }; var createKeyResponse = kmsClient.CreateKey(req); return(createKeyResponse.KeyInfo.KeyId); } 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); }
private static void BatchDeleteTags(KmsClient kmsClient) { var tagItems = new List <TagItem>(); var tagItem1 = new TagItem(); tagItem1.Key = "key1"; tagItem1.Value = "value1"; var tagItem2 = new TagItem(); tagItem2.Key = "key2"; tagItem2.Value = "value2"; tagItems.Add(tagItem1); tagItems.Add(tagItem2); try { var req = new BatchCreateKmsTagsRequest { VersionId = "v1.0", KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), Body = new BatchCreateKmsTagsRequestBody { Action = "delete", Tags = tagItems } }; var resp = kmsClient.BatchCreateKmsTags(req); Console.WriteLine(resp.HttpStatusCode); } 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); } }
static void Main1(string[] args) { const string ak = "{your ak string}"; const string sk = "{your sk string}"; const string endpoint = "{your endpoint string}"; const string projectId = "{your projectID string}"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk, projectId); var kmsClient = KmsClient.NewBuilder() .WithCredential(auth) .WithEndPoint(endpoint) .WithHttpConfig(config).Build(); DecryptData(kmsClient); }
private static string CreateGrant(KmsClient kmsClient) { var operations = new List <string> { "describe-key", "create-datakey" }; try { var request = new CreateGrantRequest { VersionId = "v1.0", Body = new CreateGrantRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), GranteePrincipal = "99104bff46109531b9ac70e606d3ffdf", GranteePrincipalType = CreateGrantRequestBody.GranteePrincipalTypeEnum.DOMAIN, Operations = operations } }; var resp = kmsClient.CreateGrant(request); Console.WriteLine(resp.GrantId); return(resp.GrantId); } 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); }
static void Main1(string[] args) { const string ak = "{your ak string}"; const string sk = "{your sk string}"; const string endpoint = "{your endpoint string}"; const string projectId = "{your projectID string}"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk, projectId); var kmsClient = KmsClient.NewBuilder() .WithCredential(auth) .WithEndPoint(endpoint) .WithHttpConfig(config).Build(); var keyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "5"); GetParametersForImport(kmsClient, keyId); ImportKeyMaterial(kmsClient, keyId); DeleteKeyMaterial(kmsClient, keyId); }
private static void GetResourceInstance(KmsClient kmsClient) { try { var req = new ListKmsByTagsRequest { VersionId = "v1.0", ResourceInstances = "resource_instances", Body = new ListKmsByTagsRequestBody { Action = "filter" } }; var resp = kmsClient.ListKmsByTags(req); foreach (var resource in resp.Resources) { Console.WriteLine(resource.ResourceId); Console.WriteLine(resource.ResourceName); Console.WriteLine(resource.ResourceDetail.ToString()); Console.WriteLine(resource.Tags); } } 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); } }
private static DecryptDatakeyResponse DecryptDataKey(KmsClient kmsClient) { try { var cipherText = CreateDataKey(kmsClient).CipherText; var request = new DecryptDatakeyRequest { VersionId = "v1.0", Body = new DecryptDatakeyRequestBody() { KeyId = GetKeyByStatus.GetKeyByKeyStatus(kmsClient, "2"), CipherText = cipherText, DatakeyCipherLength = "64" } }; var resp = kmsClient.DecryptDatakey(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); }