Score:0

I want to use openssl pkcs12 to convert lots of pem files into pfx files - but is it possible to pass in a password via the command line?

ru flag

I want to use openssl pkcs12 to convert lots of pem files into pfx files - but is it possible to pass in a password via the command line?

I have quite a lot of pem files:

So I want to enter a password into Powershell once that is then used to pass in via the command line -> rather than have to keep manually typing it in twice for each pem.

Is this even possible?

I have tried -pass pass: which does not work:-

openssl pkcs12 -export -out outfile.pfx -inkey pem.key -in pem.cert -pass pass: somePassword

FYI: This is my current Powershell script:-

$TopLevel = "C:\CertConversion\"
$OutputFolder = "$TopLevel"+"Processed\"
$CertFolder = "$TopLevel"+"CertsToProcess\"

$PasswordIWantToUse = Read-Host "PEM Conversion - Please enter a password"

$list = Get-ChildItem -Path $CertFolder

ForEach($i in $list)
{
     $pemName =  $i.Name
     
     $list = Get-ChildItem -Path $CertFolder

     $simpleName = $pemName.Replace(".pem","")

     $OutputFile = "$OutputFolder"+"$simpleName"+".pfx"

     openssl pkcs12 -export -out $OutputFile -inkey "$CertFolder$pemName" -in "$CertFolder$pemName"

}

Note: For each pem I currently get prompted "Enter Export Password:" then re-prompted "Verifying - Enter Export Password:"


I gave this another go - based on suggestions in the answer from @JMusgrove

The answer turned out to be: -password pass:

So in full:

openssl pkcs12 -export -out $OutputFile -inkey "$CertFolder$pemName" -in "$CertFolder$pemName" -password pass:$PasswordIWantToUse
Score:1
ng flag

According to the builtin help, the arguments are:

-password p   set import/export password source
-passin p     input file pass phrase source
-passout p    output file pass phrase source

You may just need to change your -pass argument to either -password or -passout

Edit: Additionally, in other examples I've seen, there's no space between "pass:" and the password itself.

ru flag
The answer for my usage turned out to be: -password pass:
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.