Openssl to dkim issue

Jonathan 480 Reputation points
2026-10-22T08:11:24.2366667+00:00

Hi,

Any key has been created to this?

User's image

Windows for business | Windows Server | User experience | PowerShell

3 answers

Sort by: Newest
  1. VPHAN 47,355 Reputation points Independent Advisor
    2026-10-22T10:37:50.0233333+00:00

    Jonathan The second half of your example is the actual text value you will paste into that newly created TXT record. The "k=rsa" tag declares the encryption type, and the "p=" tag represents your public key payload. To generate your unique version of this string, you simply type "v=DKIM1; k=rsa; p=" and immediately append the large block of alphanumeric text you previously extracted from between the headers of your dkim_public.pem file. Once combined, you save this complete string into your DNS zone to activate your DomainKeys Identified Mail signature.

    VPHAN

    Was this answer helpful?

    0 comments No comments

  2. VPHAN 47,355 Reputation points Independent Advisor
    2026-10-22T08:49:41.2533333+00:00

    Hi Jonathan,

    The output in your second image confirms you have correctly generated and viewed the public key for DKIM. The Get-Content command successfully read the stored dkim_public.pem file and displayed your key enveloped by the standard public key headers. To finalize your DomainKeys Identified Mail setup, you will need to copy the large block of alphanumeric text located strictly between those BEGIN and END lines and paste it into the appropriate TXT record within your DNS provider's portal. Please ensure you only publish this public key in your DNS records while keeping the private key from your initial command completely secured on your local server.

    Hope this answer has brought you some useful information. If it did, please hit “accept answer”. Should you have any questions, feel free to leave a comment.

    VPHAN

    Was this answer helpful?


  3. AI answer

    2026-10-22T08:17:20.6633333+00:00

    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 $LASTEXITCODE should be 0, provided no other native program has run since genrsa. PowerShell conventionally treats exit code 0 as success and nonzero as failure.^2^
    • Test-Path should return True.^3^
    • Get-Item should 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

    1. openssl-genrsa - OpenSSL Documentation
    2. about_Error_Handling
    3. Test-Path-Syntax
    4. Get-Item-Description
    5. OpenSSL issue - Microsoft Q&A
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.