I'm trying to encrypt a plaintext using DES algorithm in PHP.
I managed to code a working example in C#:
String plaintext = "1y7wpc4iddseyrwez1lor8ow3297t.pd0bfl";
String pass = "rpsxi.t.rjsmklexarygfqyrrkhwdjh";
byte[] bytesPlain = Encoding.UTF8.GetBytes(plaintext);
byte[] bytesPass = Encoding.UTF8.GetBytes(pass).Take(8).ToArray();
DESCryptoServiceProvider p = new DESCryptoServiceProvider();
p.Mode = CipherMode.ECB;
ICryptoTransform t = p.CreateEncryptor(bytesPass, bytesPass);
CryptoStreamMode m = CryptoStreamMode.Write;
MemoryStream stream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(stream, t, m);
cryptoStream.Write(bytesPlain, 0, bytesPlain.Length);
cryptoStream.FlushFinalBlock();
byte[] encBytesPlain = new byte[stream.Length];
stream.Position = 0;
stream.Read(encBytesPlain, 0, encBytesPlain.Length);
string encrypted = Convert.ToBase64String(encBytesPlain);
System.Diagnostics.Debug.WriteLine(encrypted);
plaintext = 1y7wpc4iddseyrwez1lor8ow3297t.pd0bfl
password = rpsxi.t.rjsmklexarygfqyrrkhwdjh
(only the first 8 bytes of the password are used to encrypt the message).
Anyway when I try to code a PHP version, using the crypt function or also this class I found on github https://github.com/phpseclib/phpseclib-php5/blob/master/phpseclib/Crypt/DES.php, i don't get the same result as the C# one.
I'm completely sure that the C# code works fine but I really don't know how to make a working version in PHP to get the same result in Base64.
Edit1: I already knew that DES isn't secure anymore but I need to use it in a web page just for learning purposes, also the way that C# code was written is completely right because I needed to follow some instructions and get that exactly result.