Present a string of text as a file to an external program?
I have a script that calls openssl to digitally sign an XML element from an XML file. Not the whole XML file, just one element.
openssl only works with files, not strings or other objects. So I get the element in Powershell, export it to a file, then call openssl on the new file. Snippet:
[xml]$schema = Get-Content myFile.xml
$head = $schema.data.head.InnerXml
$head | Out-File temp.txt
./openssl.exe dgst -sha256 -sign mykey.key -passin:1234 -out sig.sig temp.txt
./openssl.exe base64 -in sig.sig -out base64sig.txt
$schema.data.signature = Get-Content base64sig.txt
This makes two temporary files (temp.txt and base64sig.txt). And if Out-File doesn't have the right flags, temp.txt is slightly different from the XML (whitespace) and thus produces a different signature.
I'd like to present the variable $head as a text file to openssl. Is this possible? Can you map a FileStream to a letter drive, then use the drive path to "fool" openssl into opening it as a file?