Bonjour a tous, voila j'ai un soucis sur le décryptage d un fichier, jutilise donc la classe RijndaelManaged pour executer mon decryptage avec ce code:
public bool DecryptFile(string inputFile, string outputFile, string sKEY, string sIV)
{
CryptoStream cryptoStream = null;
try
{
FileStream fsInput = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
FileStream fsOutput = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
string hexKey = "0x" + sKEY;
string hexIV = "0x" + sIV;
byte[] KEY = ParseHex(sKEY);
byte[] KEYIV = ParseHex(sIV);
RijndaelManaged aes new RijndaelManaged() { IV KEYIV, Key = KEY,Mode = CipherMode.CFB,Padding = PaddingMode.None};
ICryptoTransform encryptor = aes.CreateDecryptor();
cryptoStream = new CryptoStream(fsOutput, encryptor, CryptoStreamMode.Write);
byte[] buffer = new byte[fsInput.Length];
long bytesProcessed = 0;
long fileLength = fsInput.Length;
int bytesInCurrentBlock;
do
{
bytesInCurrentBlock = fsInput.Read(buffer, 0, buffer.Length);
cryptoStream.Write(buffer, 0, bytesInCurrentBlock);
bytesProcessed = bytesProcessed + bytesInCurrentBlock;
}
while (bytesProcessed < fileLength);
cryptoStream.Clear();
cryptoStream.Dispose();
cryptoStream.Close();
}
catch (Exception ex)
{
string message3 = Common.Translator.GetString("ERRORUNCRYPT");
AddToConsole(message3 + ex.Message, LEVEL.ERROR);
return false;
}
return true;
}
public byte[] ParseHex(string hex)
{
int offset = hex.StartsWith("0x") ? 2 : 0;
if ((hex.Length % 2) != 0)
{
//AddToConsole("Invalid length: " + hex.Length, LEVEL.ERROR);
}
byte[] ret = new byte[(hex.Length - offset) / 2];
for (int i = 0; i < ret.Length; i++)
{
ret[i] = (byte)((ParseNybble(hex[offset]) << 4)
| ParseNybble(hex[offset + 1]));
offset += 2;
}
return ret;
}
static int ParseNybble(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
if (c >= 'A' && c <= 'F')
{
return c - 'A' + 10;
}
if (c >= 'a' && c <= 'f')
{
return c - 'a' + 10;
}
throw new ArgumentException("Invalide hex: " + c);
}
Le problème est que je pers 2 bytes sur mon décryptage
avec cette exception : Longueur des données à déchiffrer non valide.
la version c++ de mon app ou en ligne de commande sous linux avec openssl tout ce déroule bien, le problème viens en c#
bon
pas bon
Quelqu'un aurais une idée ?