Je CHIFFREMENT Mes données en PHP comme ceci:chaîne cryptée ASP.Net utilisant Décryptage par Php
$encrypted_string = mcrypt_encrypt(MCRYPT_DES, 'abcdefgh' , $input, MCRYPT_MODE_CBC, 'qwerasdf');
$encrypted_string = base64_encode($encrypted_string);
return $encrypted_string;
Et Déchiffrement le même en C# comme ceci:
public string Decrypt(string input)
{
input = Server.UrlDecode(input);
byte[] binary = Convert.FromBase64String(input);
input = Encoding.GetEncoding(28591).GetString(binary);
DES tripleDes = DES.Create();
tripleDes.IV = Encoding.ASCII.GetBytes("NAVEEDNA");
tripleDes.Key = Encoding.ASCII.GetBytes("abcdegef");
tripleDes.Mode = CipherMode.CBC;
tripleDes.Padding = PaddingMode.Zeros;
ICryptoTransform crypto = tripleDes.CreateDecryptor();
byte[] decodedInput = Decoder(input);
byte[] decryptedBytes = crypto.TransformFinalBlock(decodedInput, 0, decodedInput.Length);
return Encoding.ASCII.GetString(decryptedBytes);
}
public byte[] Decoder(string input)
{
byte[] bytes = new byte[input.Length/2];
int targetPosition = 0;
for (int sourcePosition = 0; sourcePosition < input.Length; sourcePosition += 2)
{
string hexCode = input.Substring(sourcePosition, 2);
bytes[targetPosition++] = Byte.Parse(hexCode, NumberStyles.AllowHexSpecifier);
}
return bytes;
}
Lorsque j'essaie de décrypter la chaîne en C#, elle lance l'exception suivante:
La chaîne d'entrée n'était pas dans un format correct.
À la ligne suivante: Byte.Parse (hexCode, NumberStyles.AllowHexSpecifier);
Une idée de comment je fais quoi de mal?