public object Execute(ExecutorContext context) { System.IO.MemoryStream _PlaintextStream = null; try { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.KeyManagementService.Model.EncryptRequest(); if (cmdletContext.EncryptionContext != null) { request.EncryptionContext = cmdletContext.EncryptionContext; } if (cmdletContext.GrantToken != null) { request.GrantTokens = cmdletContext.GrantToken; } if (cmdletContext.KeyId != null) { request.KeyId = cmdletContext.KeyId; } if (cmdletContext.Plaintext != null) { _PlaintextStream = new System.IO.MemoryStream(cmdletContext.Plaintext); request.Plaintext = _PlaintextStream; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); } finally { if (_PlaintextStream != null) { _PlaintextStream.Dispose(); } } }
public byte[] EncryptKey(byte[] plainText, IDictionary<string, string> context) { var req = new EncryptRequest { KeyId = _keyId, Plaintext = new MemoryStream(plainText), EncryptionContext = AsDictionary(context) }; return _client.Encrypt(req).CiphertextBlob.ToArray(); }
/// <summary> /// Initiates the asynchronous execution of the Encrypt operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Encrypt operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<EncryptResponse> EncryptAsync(EncryptRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new EncryptRequestMarshaller(); var unmarshaller = EncryptResponseUnmarshaller.Instance; return InvokeAsync<EncryptRequest,EncryptResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Encrypts plaintext into ciphertext by using a customer master key. The <code>Encrypt</code> /// function has two primary use cases: <ul> <li>You can encrypt up to 4 KB of arbitrary /// data such as an RSA key, a database password, or other sensitive customer information.</li> /// <li>If you are moving encrypted data from one region to another, you can use this /// API to encrypt in the new region the plaintext data key that was used to encrypt the /// data in the original region. This provides you with an encrypted copy of the data /// key that can be decrypted in the new region and used there to decrypt the encrypted /// data. </li> </ul> /// /// /// <para> /// Unless you are moving encrypted data from one region to another, you don't use this /// function to encrypt a generated data key within a region. You retrieve data keys already /// encrypted by calling the <a>GenerateDataKey</a> or <a>GenerateDataKeyWithoutPlaintext</a> /// function. Data keys don't need to be encrypted again by calling <code>Encrypt</code>. /// /// </para> /// /// <para> /// If you want to encrypt data locally in your application, you can use the <code>GenerateDataKey</code> /// function to return a plaintext data encryption key and a copy of the key encrypted /// under the customer master key (CMK) of your choosing. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the Encrypt service method.</param> /// /// <returns>The response from the Encrypt service method, as returned by KeyManagementService.</returns> /// <exception cref="Amazon.KeyManagementService.Model.DependencyTimeoutException"> /// The system timed out while trying to fulfill the request. /// </exception> /// <exception cref="Amazon.KeyManagementService.Model.DisabledException"> /// A request was rejected because the specified key was marked as disabled. /// </exception> /// <exception cref="Amazon.KeyManagementService.Model.InvalidGrantTokenException"> /// A grant token provided as part of the request is invalid. /// </exception> /// <exception cref="Amazon.KeyManagementService.Model.InvalidKeyUsageException"> /// The request was rejected because the specified KeySpec parameter is not valid. The /// currently supported value is ENCRYPT/DECRYPT. /// </exception> /// <exception cref="Amazon.KeyManagementService.Model.KeyUnavailableException"> /// The request was rejected because the key was disabled, not found, or otherwise not /// available. /// </exception> /// <exception cref="Amazon.KeyManagementService.Model.KMSInternalException"> /// The request was rejected because an internal exception occurred. This error can be /// retried. /// </exception> /// <exception cref="Amazon.KeyManagementService.Model.NotFoundException"> /// The request was rejected because the specified entity or resource could not be found. /// </exception> public EncryptResponse Encrypt(EncryptRequest request) { var marshaller = new EncryptRequestMarshaller(); var unmarshaller = EncryptResponseUnmarshaller.Instance; return Invoke<EncryptRequest,EncryptResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the Encrypt operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Encrypt operation on AmazonKeyManagementServiceClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndEncrypt /// operation.</returns> public IAsyncResult BeginEncrypt(EncryptRequest request, AsyncCallback callback, object state) { var marshaller = new EncryptRequestMarshaller(); var unmarshaller = EncryptResponseUnmarshaller.Instance; return BeginInvoke<EncryptRequest>(request, marshaller, unmarshaller, callback, state); }
private Amazon.KeyManagementService.Model.EncryptResponse CallAWSServiceOperation(IAmazonKeyManagementService client, Amazon.KeyManagementService.Model.EncryptRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Key Management Service", "Encrypt"); try { #if DESKTOP return(client.Encrypt(request)); #elif CORECLR return(client.EncryptAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }