# Pulling keys from \*.pem file to store in AWS Secrets Manager

**URL:** <https://forums.powershell.org/t/pulling-keys-from-pem-file-to-store-in-aws-secrets-manager/17361>\
**Category:** PowerShell Help\
**Created:** [August 20, 2021, 1:28pm UTC](https://forums.powershell.org/t/pulling-keys-from-pem-file-to-store-in-aws-secrets-manager/17361 "2021-08-20T13:28:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan-iverson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-iverson/32/11_2.png) [@dan-iverson](https://forums.powershell.org/u/dan-iverson)\
**Post date:** [August 20, 2021, 1:28pm UTC](https://forums.powershell.org/t/pulling-keys-from-pem-file-to-store-in-aws-secrets-manager/17361/1 "2021-08-20T13:28:55Z")

</div>

I am trying to find a way to pull the public and private key from a self-signed cert I created on a Windows server 2019 to store in secrets manager for other servers to be able to use for credentials encryption in PowerShell DSC \*.mof files. I can export the cert as a \*.pem file. I have been told this can be done with openssl commands, I would rather do it with PowerShell, but if there are advantages to using openssl, I am glad to hear it.

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [August 20, 2021, 9:11pm UTC](https://forums.powershell.org/t/pulling-keys-from-pem-file-to-store-in-aws-secrets-manager/17361/2 "2021-08-20T21:11:16Z")

</div>

If you have it as a PEM file that looks something like this example:  
[Example PEM File (docs.progress.com)](https://docs.progress.com/bundle/datadirect-hybrid-data-pipeline-46/page/PEM-file-format.html)

Could you use a regex to pull the necessary info?

```auto
$pem = Get-Content E:\Temp\Files\example.pem -Raw

$pem -match "(-+BEGIN PRIVATE KEY-+[\s\S]*-+END PRIVATE KEY-+)|(-+BEGIN CERTIFICATE-+[\s\S]*-+END CERTIFICATE-+)"

$matches[0]
$matches[1]

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:21pm UTC](https://forums.powershell.org/t/pulling-keys-from-pem-file-to-store-in-aws-secrets-manager/17361/3 "2024-05-16T20:21:59Z")

</div>

Closed on May 16, 2024, 8:21pm UTC


