Powershell Cryptography
Table of Contents
Generate a CSR
Create a file named
request.infin~/Downloads.Paste the following in
request.inf. Update{Username}with the users info.[Version] Signature = "$Windows NT$" [NewRequest] Subject = "C=US,S=UT,L=Salt Lake City,O=Xenter,CN={Username}" Exportable = True KeyAlgorithm = ECDSA_P256 KeyLength = 256 KeySpec = AT_KEYEXCHANGE KeyUsage = "CERT_DIGITAL_SIGNATURE_KEY_USAGE|CERT_DATA_ENCIPHERMENT_KEY_USAGE" MachineKeySet = False ProviderName = "Microsoft Software Key Storage Provider" ProviderType = 12 Silent = True SMIME = True RequestType = PKCS10In powershell, create the CSR:
certreq -new request.inf request.csrAfter submitting the CSR to get a new certificate, you can import the cert with this command:
import-certificate -filepath cert.crt -certstorelocation cert:\CurrentUser\myConfirm the certificate was installed:
Get-ChildItem -Path cert: -Recurse | select Subject, FriendlyName, SerialNumber | where {$_.Subject –like '*username*'}If needed, the certificate can be installed on a second computer or another system. You will need to export a PFX copy and import it onto the other devices. (Reissuing again will revoke the certificate you just installed.) To export a PFX copy of the certificate, run this powershell command with admin privileges (replace serial_number with the corresponding serial number you want to export):
certutil -exportpfx -user my serial_number test.pfx