Skip to content

Instantly share code, notes, and snippets.

@rbirkby
Last active April 15, 2016 08:01
Show Gist options
  • Save rbirkby/d43be44d2ba14d288ebba4f0843719e0 to your computer and use it in GitHub Desktop.
Save rbirkby/d43be44d2ba14d288ebba4f0843719e0 to your computer and use it in GitHub Desktop.
# Also see https://cyber-defense.sans.org/blog/2015/08/23/powershell-protect-cmsmessage-example-code
$cert = New-SelfSignedCertificate -subject 'CN=TestCert' -Type DocumentEncryptionCert -NotAfter 2100-07-01 -TextExtension @("2.5.29.37={text}1.3.6.1.4.1.311.80.1") -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider"
Export-Certificate -cert $cert -FilePath cert.cer
$ciphertext = Protect-CmsMessage -Content 'password' -To $cert.Thumbprint
$ciphertext
$plaintext = Unprotect-CmsMessage -Content $ciphertext
$plaintext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment