The command likely completed successfully: -out dkim_private.pem writes the private key to a file instead of displaying it in PowerShell.^1^
Verify the generated private key
Run these commands from the same C:\Program Files\OpenSSL-Win64\bin window:
$LASTEXITCODE
Test-Path .\dkim_private.pem
Get-Item .\dkim_private.pem |
Select-Object FullName, Length, LastWriteTime
.\openssl pkey -in .\dkim_private.pem -check -noout
$LASTEXITCODE
Expected results:
- The first
$LASTEXITCODEshould be0, provided no other native program has run sincegenrsa. PowerShell conventionally treats exit code0as success and nonzero as failure.^2^ -
Test-Pathshould returnTrue.^3^ -
Get-Itemshould show a nonzero file size and the full file location.^4^ - The validation command should report that the key is valid and return exit code
0.
Do not display, email, or publish dkim_private.pem; it must remain private and be accessible only to the mail server or signing application.
Derive the DKIM public key
Create the corresponding public key from the private key:
.\openssl pkey `
-in .\dkim_private.pem `
-pubout `
-out .\dkim_public.pem
$LASTEXITCODE
Get-Item .\dkim_public.pem |
Select-Object FullName, Length, LastWriteTime
A successful operation produces dkim_public.pem with exit code 0. The public key can be inspected safely:
Get-Content .\dkim_public.pem
It will have PEM headers similar to:
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----
Your other mail server or application determines the DKIM selector, DNS record name, and whether it expects the PEM file or only the Base64 content between those headers. Follow that product’s DKIM instructions; publish only the public-key material, never the private key.
If Test-Path returns False, run the executable by its explicit name and capture the exit code immediately:
.\openssl.exe genrsa -out "$PWD\dkim_private.pem" 2048
"OpenSSL exit code: $LASTEXITCODE"
Test-Path "$PWD\dkim_private.pem"
If PowerShell instead reports that openssl.exe cannot be found, verify the installation or invoke it using its full path; an installed OpenSSL binary may also need its bin directory added to PATH.^5^
References