title: How can I convert PrivateKeyCiphertextBlob or PrivateKeyPlaintext to string?
body: <p>I'm attempting to use the KMS GenerateDataKeyPairAsync in order to get the public and private key out for testing (Once it works I will switch to the GenerateDataKeyPairWithoutPlaintextAsync).</p>
  
  <p>The GenerateDataKeyPairResponse has three memory streams for the Public Key, Private Key Ciphertext and Private Key plaintext.</p>
  
  <p>I can't seem to convert any of these memory streams to string so I can actually then use the keys.</p>
  
  <p>The SDK docs (<a href="https://docs.aws.amazon.com/sdkfornet/v3/apidocs/Index.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/sdkfornet/v3/apidocs/Index.html</a>) say it will be Base64 encoded if using the HTTP api, does the SDK use the HTTP api? I can't seem to tell.</p>
  
  <p>I have tried using StreamReader.ReadToEnd() and using Encoding.ENCODING.FromString(stream.ToArray()) using all the encodings but I can't seem to get a reasonable value out.</p>
  
  <p>Am I missing something important here?</p>
  
  <p>Thanks</p>
  
  <p>Adding the code:</p>
  
  <pre><code># USING: AWSSDK.KeyManagementService VERSION: 3.5.0-beta
  
  
  using System;
  using System.IO;
  using System.Threading.Tasks;
  using Amazon;
  using Amazon.KeyManagementService;
  using Amazon.KeyManagementService.Model;
  using Amazon.Runtime;
  
  namespace ConsoleApp1
  {
      class Program
      {
          static async Task Main(string[] args)
          {
              var credentials = new BasicAWSCredentials("AccessKey", "SecretKey");
  
              var kmsClient = new AmazonKeyManagementServiceClient(credentials, RegionEndpoint.EUCentral1);
  
              const string keyId = "CMKKey";
  
              var dataKeyRequest = new GenerateDataKeyPairRequest
              {
                  KeyId = keyId, 
                  KeyPairSpec = DataKeyPairSpec.RSA_2048
              };
  
              var dataKeyPairResponse = await kmsClient.GenerateDataKeyPairAsync(dataKeyRequest);
  
              var publicKeyStream = dataKeyPairResponse.PublicKey;
  
              var privateKeyStream = dataKeyPairResponse.PrivateKeyPlaintext;
  
              var publicReader = new StreamReader( publicKeyStream );
              var publicKey = publicReader.ReadToEnd();
  
              var privateReader = new StreamReader( privateKeyStream );
              var privateKey = privateReader.ReadToEnd();
  
              Console.WriteLine(publicKey);
              Console.WriteLine(privateKey);
          }
      }
  }
  </code></pre>