certs
Differences
This shows you the differences between two versions of the page.
| certs [12/30/2024 05:39] – created johnsonjohn | certs [12/31/2025 05:40] (current) – removed johnsonjohn | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ======Certs====== | ||
| - | ---- | ||
| - | =====PowerShell Certs===== | ||
| - | ====CSR Generator==== | ||
| - | < | ||
| - | ## PowerShell Script to generate a Certificate Signing Request (CSR) using the SHA256 (SHA-256) signature algorithm and a 2048 bit key size (RSA) via the Cert Request Utility (certreq) ## | ||
| - | |||
| - | <# | ||
| - | JWJ0215 2023 | ||
| - | #> | ||
| - | |||
| - | ### | ||
| - | ## | ||
| - | # YOU WILL NEED TO START ISE AS OTHER USER TO RUN.... | ||
| - | |||
| - | #################### | ||
| - | # Prerequisite check | ||
| - | #################### | ||
| - | if (-NOT([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]:: | ||
| - | Write-Host " | ||
| - | Pause | ||
| - | Throw " | ||
| - | } | ||
| - | |||
| - | ####################### | ||
| - | # Setting the variables | ||
| - | ####################### | ||
| - | $UID = [guid]:: | ||
| - | $files = @{} | ||
| - | $files[' | ||
| - | $files[' | ||
| - | |||
| - | $request = @{} | ||
| - | $request[' | ||
| - | |||
| - | Write-Host " | ||
| - | $request[' | ||
| - | $request[' | ||
| - | $request[' | ||
| - | $request[' | ||
| - | $request[' | ||
| - | $request[' | ||
| - | |||
| - | ########################### | ||
| - | # Subject Alternative Names | ||
| - | ########################### | ||
| - | $i = 0 | ||
| - | Do { | ||
| - | $i++ | ||
| - | $request[' | ||
| - | if ($request[' | ||
| - | | ||
| - | } | ||
| - | | ||
| - | } until ($request[' | ||
| - | |||
| - | # Remove the last in the array (which is empty) | ||
| - | $request[' | ||
| - | |||
| - | ######################### | ||
| - | # Create the settings.inf | ||
| - | ######################### | ||
| - | $settingsInf = " | ||
| - | [Version] | ||
| - | Signature=`" | ||
| - | [NewRequest] | ||
| - | KeyLength = 2048 | ||
| - | Exportable = TRUE | ||
| - | MachineKeySet = TRUE | ||
| - | SMIME = FALSE | ||
| - | RequestType = PKCS10 | ||
| - | ProviderName = `" | ||
| - | ProviderType = 12 | ||
| - | HashAlgorithm = sha256 | ||
| - | ;Variables | ||
| - | Subject = `" | ||
| - | [Extensions] | ||
| - | {{SAN}} | ||
| - | ;Certreq info | ||
| - | ; | ||
| - | ;CSR Decoder | ||
| - | ; | ||
| - | ; | ||
| - | " | ||
| - | |||
| - | $request[' | ||
| - | if ($request[' | ||
| - | $san = " | ||
| - | " | ||
| - | Foreach ($sanItem In $request[' | ||
| - | $san += " | ||
| - | " | ||
| - | } | ||
| - | return $san | ||
| - | } | ||
| - | } | ||
| - | |||
| - | $settingsInf = $settingsInf.Replace(" | ||
| - | |||
| - | # Save settings to file in temp | ||
| - | $settingsInf > $files[' | ||
| - | |||
| - | # Done, we can start with the CSR | ||
| - | Clear-Host | ||
| - | |||
| - | ################################# | ||
| - | # CSR TIME | ||
| - | ################################# | ||
| - | |||
| - | # Display summary | ||
| - | Write-Host " | ||
| - | Common name: $($request[' | ||
| - | Organisation: | ||
| - | Organisational unit: $($request[' | ||
| - | City: $($request[' | ||
| - | State: $($request[' | ||
| - | Country: $($request[' | ||
| - | Subject alternative name(s): $($request[' | ||
| - | Signature algorithm: SHA256 | ||
| - | Key algorithm: RSA | ||
| - | Key size: 2048 | ||
| - | " -ForegroundColor Yellow | ||
| - | |||
| - | certreq -new $files[' | ||
| - | |||
| - | # Output the CSR | ||
| - | $CSR = Get-Content $files[' | ||
| - | Write-Output $CSR | ||
| - | Write-Host " | ||
| - | " | ||
| - | |||
| - | # Set the Clipboard (Optional) | ||
| - | Write-Host "Copy CSR to clipboard? (y|n): " -ForegroundColor Yellow -NoNewline | ||
| - | if ((Read-Host) -ieq " | ||
| - | $csr | clip | ||
| - | Write-Host "Check your ctrl+v | ||
| - | " | ||
| - | } | ||
| - | |||
| - | |||
| - | ######################## | ||
| - | # Remove temporary files | ||
| - | ######################## | ||
| - | $files.Values | ForEach-Object { | ||
| - | Remove-Item $_ -ErrorAction SilentlyContinue | ||
| - | } | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | ====CertReq2023==== | ||
| - | < | ||
| - | # User CertReq in Powershell to create your cert using the SHA256 (SHA-256) signature algorithm and a 2048 bit key size (RSA) ## | ||
| - | |||
| - | <# | ||
| - | JWJ0215 2023 | ||
| - | #> | ||
| - | |||
| - | # This will create your inf and save to your personal folder | ||
| - | |||
| - | $Date = (Get-Date).ToString(' | ||
| - | |||
| - | $ReqFile = " | ||
| - | $InfFile = @" | ||
| - | [NewRequest]`r | ||
| - | Subject = " | ||
| - | KeySpec = 1 | ||
| - | KeyLength = 2048 | ||
| - | Exportable = TRUE`r | ||
| - | RequestType = CMC`r | ||
| - | "@ | ||
| - | Write-Host " | ||
| - | $FinalInfFile = " | ||
| - | New-Item $FinalInfFile -type file -value $InfFile | ||
| - | cmd /c " | ||
| - | Write-Host " " | ||
| - | Write-Host " | ||
| - | </ | ||
| - | ---- | ||
| - | |||
| - | =====Certs TEXT===== | ||
| - | |||
| - | ====Certs.txt==== | ||
| - | < | ||
| - | C: | ||
| - | |||
| - | changeit | ||
| - | |||
| - | Delete the Cert | ||
| - | keytool -delete -noprompt -alias ${thedacaresandcrt} -storepass ${changeit} | ||
| - | |||
| - | </ | ||
| - | |||
| - | ---- | ||
certs.1735565954.txt.gz · Last modified: by johnsonjohn
