Feed private key to pageant via STDIN

77 views Asked by At

Is there a way in Windows to trick or simulate the file, made from other command output?

What I am looking for is the following bash equivalent, but for Windows and pageant:

sops --decrypt "${f}" | ssh-add -

While Windows CLI has just this:

pageant.exe file1.ppk .... fileN.ppk

So, I do not have to output decrypted content to the file to securely sdelete after

Actually, if there is a better cli-fed alternative. CMD or Powershell based. Keypass with agent plugin does not fit my workflow

2

There are 2 answers

1
MaxCreatesCode On

For strings/keys:

  PS> ConvertFrom-SecureString $f -key $key

For larger files you have a couple of options:

Windows Server:

  > cipher /d

.NET: Uses your CSP which may not be desirable

  PS> [System.IO.File]::Decrypt($f)

I can list many more options if need be but I don't know what you are trying to do. Better to use higher-level solutions but https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography can do what you want for sure.

Also clearly ssh-agent needs to be running for ssh-add. Can use the ssh-agent (which is now built-in on Windows Server but also comes with Git) or OpenSSH's ssh-agent but neither service is started by default.

0
Vetal On
sops --decrypt keyfile  |  ssh-add.exe -

works for me.

Now, is to mate the GIT_SSH and Putty with OpenSSH client, and the problem is solved