Last active
April 15, 2016 08:01
-
-
Save rbirkby/d43be44d2ba14d288ebba4f0843719e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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