|
1 |
| -### Cryptographic Message Syntax (CMS) cmdlets |
| 1 | +# Cryptographic Message Syntax (CMS) cmdlets |
2 | 2 |
|
3 | 3 | The Cryptographic Message Syntax cmdlets support encryption and decryption of content using the IETF standard format for cryptographically protecting messages as documented by [RFC5652](http://tools.ietf.org/html/rfc5652).
|
4 |
| - |
| 4 | +```powershell |
5 | 5 | Get-CmsMessage \[-Content\] <string>
|
6 |
| - |
7 | 6 | Get-CmsMessage \[-Path\] <string>
|
8 |
| - |
9 | 7 | Get-CmsMessage \[-LiteralPath\] <string>
|
10 |
| - |
11 | 8 | Protect-CmsMessage \[-To\] <CmsMessageRecipient\[\]> \[-Content\] <string> \[\[-OutFile\] <string>\]
|
12 |
| - |
13 | 9 | Protect-CmsMessage \[-To\] <CmsMessageRecipient\[\]> \[-Path\] <string> \[\[-OutFile\] <string>\]
|
14 |
| - |
15 | 10 | Protect-CmsMessage \[-To\] <CmsMessageRecipient\[\]> \[-LiteralPath\] <string> \[\[-OutFile\] <string>\]
|
16 |
| - |
17 | 11 | Unprotect-CmsMessage \[-EventLogRecord\] <EventLogRecord> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
|
18 |
| - |
19 | 12 | Unprotect-CmsMessage \[-Content\] <string> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
|
20 |
| - |
21 | 13 | Unprotect-CmsMessage \[-Path\] <string> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
|
22 |
| - |
23 | 14 | Unprotect-CmsMessage \[-LiteralPath\] <string> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
|
24 |
| - |
| 15 | +``` |
25 | 16 | The CMS encryption standard implements public key cryptography, where the keys used to encrypt content (the *public key*) and the keys used to decrypt content (the *private key*) are separate.
|
26 | 17 |
|
27 | 18 | Your public key can be shared widely, and is not sensitive data. If any content is encrypted with this public key, only your private key can decrypt it. For more information about Public Key Cryptography, see: <http://en.wikipedia.org/wiki/Public-key_cryptography>.
|
28 | 19 |
|
29 | 20 | To be recognized in Windows PowerShell, encryption certificates require a unique key usage identifier (EKU) to identify them as data encryption certificates (like the identifiers for 'Code Signing', 'Encrypted Mail').
|
30 | 21 |
|
31 | 22 | Here is an example of creating a certificate that is good for Document Encryption:
|
32 |
| - |
| 23 | +```powershell |
33 | 24 | (Change the text in **Subject** to your name, email, or other identifier), and put in a file (i.e.: DocumentEncryption.inf):
|
34 |
| - |
35 | 25 | \[Version\]
|
36 |
| - |
37 | 26 | Signature = "$Windows NT$"
|
38 |
| - |
39 | 27 | \[Strings\]
|
40 |
| - |
41 | 28 | szOID\_ENHANCED\_KEY\_USAGE = "2.5.29.37"
|
42 |
| - |
43 | 29 | szOID\_DOCUMENT\_ENCRYPTION = "1.3.6.1.4.1.311.80.1"
|
44 |
| - |
45 | 30 | \[NewRequest\]
|
46 |
| - |
47 | 31 |
|
48 |
| - |
49 | 32 | MachineKeySet = false
|
50 |
| - |
51 | 33 | KeyLength = 2048
|
52 |
| - |
53 | 34 | KeySpec = AT\_KEYEXCHANGE
|
54 |
| - |
55 | 35 | HashAlgorithm = Sha1
|
56 |
| - |
57 | 36 | Exportable = true
|
58 |
| - |
59 | 37 | RequestType = Cert
|
60 |
| - |
61 | 38 | KeyUsage = "CERT\_KEY\_ENCIPHERMENT\_KEY\_USAGE | CERT\_DATA\_ENCIPHERMENT\_KEY\_USAGE"
|
62 |
| - |
63 | 39 | ValidityPeriod = "Years"
|
64 |
| - |
65 | 40 | ValidityPeriodUnits = "1000"
|
66 |
| - |
67 | 41 | \[Extensions\]
|
68 |
| - |
69 | 42 | %szOID\_ENHANCED\_KEY\_USAGE% = "{text}%szOID\_DOCUMENT\_ENCRYPTION%"
|
70 |
| - |
| 43 | +``` |
71 | 44 | Then run:
|
72 |
| - |
| 45 | +```powershell |
73 | 46 | certreq -new DocumentEncryption.inf DocumentEncryption.cer
|
74 |
| - |
| 47 | +``` |
75 | 48 | And you can now encrypt and decrypt content:
|
76 |
| - |
77 |
| -> 106 \[C:\\temp\] |
78 |
| -> >> $protected = "Hello World" | Protect-CmsMessage -To "\*[email protected]\*[](mailto:*[email protected]*)" |
79 |
| -> |
80 |
| -> 107 \[C:\\temp\] |
81 |
| -> >> $protected |
82 |
| -> -----BEGIN CMS----- |
83 |
| -> MIIBqAYJKoZIhvcNAQcDoIIBmTCCAZUCAQAxggFQMIIBTAIBADA0MCAxHjAcBgNVBAMMFWxlZWhv |
84 |
| -> bG1AbWljcm9zb2Z0LmNvbQIQQYHsbcXnjIJCtH+OhGmc1DANBgkqhkiG9w0BAQcwAASCAQAnkFHM |
85 |
| -> proJnFy4geFGfyNmxH3yeoPvwEYzdnsoVqqDPAd8D3wao77z7OhJEXwz9GeFLnxD6djKV/tF4PxR |
86 |
| -> E27aduKSLbnxfpf/sepZ4fUkuGibnwWFrxGE3B1G26MCenHWjYQiqv+Nq32Gc97qEAERrhLv6S4R |
87 |
| -> G+2dJEnesW8A+z9QPo+DwYU5FzD0Td0ExrkswVckpLNR6j17Yaags3ltNVmbdEXekhi6Psf2MLMP |
88 |
| -> TSO79lv2L0KeXFGuPOrdzPAwCkV0vNEqTEBeDnZGrjv/5766bM3GW34FXApod9u+VSFpBnqVOCBA |
89 |
| -> DVDraA6k+xwBt66cV84OHLkh0kT02SIHMDwGCSqGSIb3DQEHATAdBglghkgBZQMEASoEEJbJaiRl |
90 |
| -> KMnBoD1dkb/FzSWAEBaL8xkFwCu0e1ZtDj7nSJc= |
91 |
| -> -----END CMS----- |
92 |
| -> |
93 |
| -> 108 \[C:\\temp\] |
94 |
| -> >> $protected | Unprotect-CmsMessage |
95 |
| -> Hello World |
96 |
| -
|
| 49 | +```powershell |
| 50 | +$protected = "Hello World" | Protect-CmsMessage -To "\*[email protected]\*[](mailto:*[email protected]*)" |
| 51 | +$protected |
| 52 | + -----BEGIN CMS----- |
| 53 | + MIIBqAYJKoZIhvcNAQcDoIIBmTCCAZUCAQAxggFQMIIBTAIBADA0MCAxHjAcBgNVBAMMFWxlZWhv |
| 54 | + bG1AbWljcm9zb2Z0LmNvbQIQQYHsbcXnjIJCtH+OhGmc1DANBgkqhkiG9w0BAQcwAASCAQAnkFHM |
| 55 | + proJnFy4geFGfyNmxH3yeoPvwEYzdnsoVqqDPAd8D3wao77z7OhJEXwz9GeFLnxD6djKV/tF4PxR |
| 56 | + E27aduKSLbnxfpf/sepZ4fUkuGibnwWFrxGE3B1G26MCenHWjYQiqv+Nq32Gc97qEAERrhLv6S4R |
| 57 | + G+2dJEnesW8A+z9QPo+DwYU5FzD0Td0ExrkswVckpLNR6j17Yaags3ltNVmbdEXekhi6Psf2MLMP |
| 58 | + TSO79lv2L0KeXFGuPOrdzPAwCkV0vNEqTEBeDnZGrjv/5766bM3GW34FXApod9u+VSFpBnqVOCBA |
| 59 | + DVDraA6k+xwBt66cV84OHLkh0kT02SIHMDwGCSqGSIb3DQEHATAdBglghkgBZQMEASoEEJbJaiRl |
| 60 | + KMnBoD1dkb/FzSWAEBaL8xkFwCu0e1ZtDj7nSJc= |
| 61 | + -----END CMS----- |
| 62 | +
|
| 63 | +$protected | Unprotect-CmsMessage |
| 64 | + Hello World |
| 65 | +``` |
97 | 66 | Any parameter of type **CMSMessageRecipient** supports identifiers in the following formats:
|
98 |
| - |
99 |
| -- An actual certificate (as retrieved from the certificate provider) |
100 |
| - |
101 |
| -- Path to the a file containing the certificate |
102 |
| - |
103 |
| -- Path to a directory containing the certificate |
104 |
| - |
105 |
| -- Thumbprint of the certificate (used to look in the certificate store) |
106 |
| - |
107 |
| -- Subject name of the certificate (used to look in the certificate store) |
108 |
| - |
109 |
| -To view document encryption certificates in the certificate provider, you can use the -**DocumentEncryptionCert** dynamic parameter: |
110 |
| - |
111 |
| -58 \[Cert:\\currentuser\\my\] |
112 |
| - |
113 |
| ->> dir -DocumentEncryptionCert |
| 67 | +- An actual certificate (as retrieved from the certificate provider) |
| 68 | +- Path to the a file containing the certificate |
| 69 | +- Path to a directory containing the certificate |
| 70 | +- Thumbprint of the certificate (used to look in the certificate store) |
| 71 | +- Subject name of the certificate (used to look in the certificate store) |
| 72 | + |
| 73 | +To view document encryption certificates in the certificate provider, you can use the **-DocumentEncryptionCert** dynamic parameter: |
| 74 | +```powershell |
| 75 | +dir -DocumentEncryptionCert |
| 76 | +``` |
0 commit comments