I'm trying to decrpyt a base64 encoded string in bash using openSSL. I have the password, and I have C# code that works (very new to C#, and luckily found dotnetfiddle - so have got it working in C#) -- and I thought it would be easy to do this in openSSL. I think I'm probably not understanding some key implicit options that C#'s CryptoStream() function uses.
So in C# to decrypt (successfully) I am using..
byte[] aesKey = Encoding.UTF8.GetBytes("MYPASSWORD123");
aesAlg.Key = aesKey;
aesAlg.IV = aesKey;
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
// Create the streams used for decryption.
using (MemoryStream msDecrypt = new MemoryStream(cipherText)) {
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) {
using (StreamReader srDecrypt = new StreamReader(csDecrypt)) {
// Read the decrypted bytes from the decrypting stream
// and place them in a string.
plaintext = srDecrypt.ReadToEnd();
}
}
}
and that works! (quite a surprise for my 2nd only bit of C#). So I thought easy in bash....
cat /tmp/encrypted | base64 -d > /tmp/foo
openssl enc -d -aes-256-cbc -k "MYPASSWORD123" -in /tmp/foo -out /tmp/foo2
also tried converting password and IV to hex and using...
openssl enc -d -aes-256-cbc -K "$hex" -iv "$hex" -in /tmp/foo -out /tmp/foo2
also tried...
openssl enc -d -base64 -aes-256-cbc -K "MYPASSWORD123" -iv "MYPASSWORD123" -in /tmp/encrypted -out /tmp/foo2
I get hex string is too short, padding with zero bytes to length, bad decrypt and bad magic number. I am using openSSL 1.1.1, and have tried -salt and -md md5 options. I but stumped here - would appreciate any insights - many thanks