I have gotten des encryption code that client will be using in c#
public string EncryptQueryString(string stringToEncrypt)
{
byte[] key = { };
byte[] IV = { 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78 };
try
{
key = Encoding.UTF8.GetBytes(KEY);
using (DESCryptoServiceProvider oDESCrypto = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream oMemoryStream = new MemoryStream();
CryptoStream oCryptoStream = new CryptoStream(oMemoryStream,
oDESCrypto.CreateEncryptor(key, IV), CryptoStreamMode.Write);
oCryptoStream.Write(inputByteArray, 0, inputByteArray.Length);
oCryptoStream.FlushFinalBlock();
return Convert.ToBase64String(oMemoryStream.ToArray());
}
}
catch
{
throw;
}
}
public string DecryptQueryString(string stringToDecrypt)
{
byte[] key = { };
byte[] IV = { 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78 };
stringToDecrypt = stringToDecrypt.Replace(" ", "+");
byte[] inputByteArray = new byte[stringToDecrypt.Length];
try
{
key = Encoding.UTF8.GetBytes(KEY);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
Encoding encoding = Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch
{
throw;
}
}
i am trying to get this to work in php - please help me in showiing me what i am doing wrong.
What I have tried:
echo "<pre>\n";
$key = "K6u8#m2b";
$textToEncrypt = "5512065314089";
$iv = "0112233445566778";
$encrypted = openssl_encrypt($textToEncrypt, 'aes-256-cbc', $key, 0, $iv);
echo "encrypted output=" . $encrypted . "\n";
echo "expected- WfRb+Vugfc1cbJNfXKL6bw=="
output
BASE64(IV)=MDExMjIzMzQ0NTU2Njc3OA==
encrypted output=Pt0MK+1qt0mAyU7irnWzTw==
decrypted output=5512065314089
expected- WfRb+Vugfc1cbJNfXKL6bw==