Why is the sha256 hash key different from Command Prompt and Powershell - powershell

So I'm currently doing a project at the moment, and I've came across integrity hashing. So I've been taught to use openssl sha256 to hash a css file for practice. I did this in Terminal, Command prompt and Powershell.
Terminal gave the same results as the Command prompt but powershell gave an entirely new result.
Command Prompt
3BmtwdrKmE6lXPHGqB1Z1jEERC8phQpUwTHMblpJ0Gw=
Terminal
3BmtwdrKmE6lXPHGqB1Z1jEERC8phQpUwTHMblpJ0Gw=
PowerShell
Pxk/Pz8/P04/XD8/Px1ZPzEERC8pPw0KVD8xP25aST9sDQo=
tl;dr
Basically I just want to know the different output between terminal and command prompt to powershell
Extra:
I'm really interested in cyber security and I want to learn more, upskill and do what it takes to be a unicorn. Feel free to give me critic/advice <3.

You're dealing with an output encoding difference between Command Prompt, PowerShell, and OpenSSL's interpretation of such when run from these shells.
To see your active code page from Command Prompt, run chcp.com. To see your active output encoding in PowerShell, check the status of the $OutputEncoding variable.
Note: You will see code page differences.
You may try in vain to set both to the same output encoding type, but OpenSSL will most likely still report differences.
As an example, you can review the OpenSSL output from all output encoding types in PowerShell with:
[System.Text.Encoding]::GetEncodings() | % { "`n`nCodePage $($_.CodePage):"; $OutputEncoding = [System.Text.Encoding]::GetEncoding($_.CodePage); openssl dgst -sha256 -binary .\index-styles.css | openssl base64 -A }
Note: I doubt there's a similar hash listed when compared to OpenSSL's Command Prompt output.
Anyhow, to avoid this problem, I would advise to use OpenSSL's built-in -out file parameter, then call OpenSSL twice, rather than rely on the pipeline (|):
openssl dgst -sha256 -binary -out .\index-styles.out .\index-styles.css
openssl base64 -A -in .\index-styles.out
You should (in theory) get consistent results from OpenSSL in both Command Prompt and PowerShell when using -out file then -in file
Hope this helps.

Related

Cannot start "ssh-keygen" Interactive console applications are not supported. Powershell

I am having troubles getting a ssh key pair in Powershell. I tried two ways but both didn't work.
PS C:\WINDOWS\system32> ssh-keygen
Cannot start "ssh-keygen". Interactive console applications are not supported.
To run the application, use the Start-Process cmdlet or use "Start PowerShell.exe" from the File menu.
To view/modify the list of blocked console applications, use $psUnsupportedConsoleApplications, or consult online help.
At line:0 char:0
I tried $psUnsupportedConsoleApplications as well, and it does show both ssh-keygen and ssh-keygen.exe .
I also tried the following, and it seemed stuck after "Generating public/private rsa key pair" and doesn't move forward nor gives any error.
PS C:\WINDOWS\system32> ssh-keygen -m PEM -t rsa -b 2048
Generating public/private rsa key pair.
Any insight unblocking this issue would be much appreciated!

Using powershell to trigger an exe whilst providing arguments and automating inputs

We're hoping to automate the creation of certificates to simplify the process for clients.
To do this, we wanted to create a powershell script that runs through the openssl commands and autofills the inputs.
Here's an example of a command that will be run
openssl req -new -out client.csr -key client.key
And here's the format within the script ($loc being openssl.exe's file location)
& $loc'\openssl.exe' #('req','-new','-out','client.csr','-key', 'client.key')
Running this command will ask the user for several inputs, which I would like to be handled by the script.
We've tried prepending the command with "input" | and echo input | as suggested in other posts, along with different formatting of the command, but to no avail.
I found this script that feeds the inputs as a configuration file, but in testing it asked for inputs anyway
I'm new to powershell, so please be gentle if I'm making a dumb mistake :)

Key hash format

I'm learning to make facebook apps and have come to the part where you have to enter your 28 character key hash.
I've searched the forums and internet after an answer but i couldn't find any.
If someone does, please send me a link and i will close this thread.
I ran the code: keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%.android\debug.keystore | openssl sha1 -binary | openssl
base64 - in powershell, and it returns a 32 character code in this format: xxx/xxxxxxx/xxx/xxx/xxx/xxxxxx== I cant get what i'm doing wrong or how i'm supposed to translate this code to another format.
Thx for help!
The problem turned out to be caused by running the command in powershell instead of cmd.

How to automate sending a password to a program that's waiting for a password

I have the following PowerShell script that I use to configure my shell with environment variables associated with the ssh-agent.
function eval-ssh-agent
{
$t0 = (ssh-agent) | Out-String
$t0 -match 'SSH_AUTH_SOCK=([a-zA-Z0-9.\-\/]*);[\w\d\s;]*SSH_AGENT_PID=([0-9]*);'
$env:SSH_AUTH_SOCK=$Matches[1]
$env:SSH_AGENT_PID=$Matches[2]
ssh-add C:\mykey
}
It works just fine, but when PowerShell runs ssh-add it always blocks on standard input asking me for my ssh key's password. I then have to enter the password and hit return. How can I automate this in the script?
Ideally I would like to do the PowerShell equivalent of the Unix-like piping a string to the program on standard in. How can this be done?
This depends entirely on how the ssh-add executable works.
If it accepts standard input for the password (this seems unlikely), then you could pipe the password to it. This would be quite insecure and definitely not recommended (if it works at all).
If ssh-add accepts a command-line argument to specify a password, you could use that (again: insecure).

Pipe works in Powershell but not CMD?

So the larger context of this problem is that it isn't possible, for whatever reason, to decrypt this file using, say, Bouncy Castle, so we're trying to do an automated command line with the normal gpg utility instead... I originally thought that would be quicker than trying to figure out why Bouncy Castle doesn't believe this is a real PGP-encrypted file, but I might have been wrong.
Here's the pipeline:
echo password | gpg --batch --yes --passphrase-fd 0 "filename"
This works perfectly in Powershell. Actually, several variations on this work perfectly in Powershell, but that's not the point...
The point is that I'm trying to run this in cmd.exe and it doesn't work there. Instead, I get an error saying that there has been no password provided and that, therefore, there is no secret key available and that, therefore, the file cannot be decrypted.
Given that the instructions I read for this are specifically for cmd.exe (not Powershell), I'm more than a little confused. Any idea what's going on here?
Apparently, the problem is that the password being passed through the pipeline includes a space--the one that appears between our hypothetical "d" and the pipe symbol itself. :)
So, for future reference, this works:
echo password|gpg --batch --yes --passphrase-fd 0 "filename"
Which, by the way, is exactly what the guide had said, but which I never caught onto because I did my initial testing in Powershell and didn't realize how picky cmd's echo command could be.