I encrypted a file with a private key on a debian machine with the command :
openssl rsautl -encrypt -inkey private.pem -in test.txt -out test.txt.ssl
I also converted my public key from pem to xml with the python script here : https://github.com/MisterDaneel/PemToXml
I'm trying to decipher the test.txt.ssl file on a windows machine and I can't install any software. So I have to use onlyRSACryptoServiceProvider. My powershell script looks like this:
$InputFileLocation = (Get-Location).tostring() + "\public.pem.xml"
$InputFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($InputFileLocation)
$pemRawStr = (Get-Content $InputFile) -join ''
$rsa = New-Object -TypeName System.Security.Cryptography.RSACryptoServiceProvider
$key = $rsa.FromXmlString($pemRawStr)
$rsa.ExportParameters($false)
[byte[]]$str = Get-Content "test.ssl" -Encoding Byte
$DecryptedStr = $rsa.Decrypt($str, $false);
Write-Host "File content : " $DecryptedStr
But it's not working. I have this error :
Exception calling "Decrypt" with "2" argument(s): "Key doesn't esist.
"
At C:\Users\RICHARDAN\Documents\Dev - Git\protectmi_analysis_processing-master\windows\test.ps1:9 char:1
+ $DecryptedStr = $rsa.Decrypt($str, $false);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CryptographicException