IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Décryptage MD5 : Length of the data to decrypt is invalid.


Sujet :

C#

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 51
    Points : 35
    Points
    35
    Par défaut Décryptage MD5 : Length of the data to decrypt is invalid.
    Salut,

    J'essaie de décrypter une string avec MD5. Ma méthode string Md5Encrypt(string Message) semble marcher uniquement quand la taille de Message est inférieure à 8 chars. Au-dessus de 7 chars la méthode lance l'exception suivante sur le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
    Error message
    Length of the data to decrypt is invalid.
    StackTrace :
    at System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
    at Gpeto.Functions.Md5Decrypt(String
    Voici la méthode (extraite du site suivant )
    Code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
     
    public static string Md5Decrypt(string Message)
            {
                try
                {
                    if (Message == null)
                        return null;
                    string Passphrase = "KeyWord";
                    byte[] Results;
                    System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
     
                    // Step 1. We hash the passphrase using MD5
                    // We use the MD5 hash generator as the result is a 128 bit byte array
                    // which is a valid length for the TripleDES encoder we use below
     
                    MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
                    byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
     
                    // Step 2. Create a new TripleDESCryptoServiceProvider object
                    TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
     
                    // Step 3. Setup the decoder
                    TDESAlgorithm.Key = TDESKey;
                    TDESAlgorithm.Mode = CipherMode.ECB;
                    TDESAlgorithm.Padding = PaddingMode.PKCS7;
     
                    // Step 4. Convert the input string to a byte[]
                    byte[] DataToDecrypt = Convert.FromBase64String(Message.Replace(' ','+'));
     
                    // Step 5. Attempt to decrypt the string
                    try
                    {
                        ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
                        Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
                    }
                    finally
                    {
                        // Clear the TripleDes and Hashprovider services of any sensitive information
                        TDESAlgorithm.Clear();
                        HashProvider.Clear();
                    }
     
                    // Step 6. Return the decrypted string in UTF8 format
                    return UTF8.GetString(Results);
     
                }
                catch (Exception v_oEx)
                {
                    throw new Exception("Unable to decrypt the word");
                }
            }

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 62
    Points : 63
    Points
    63
    Par défaut
    Salut.

    http://forums.asp.net/p/1209796/2192434.aspx

    Apparemment,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     byte[] DataToDecrypt = Convert.FromBase64String(Message.Replace(' ','+'));
    serait la source du problème.

Discussions similaires

  1. Length of the data to decrypt is invalid. Erreur
    Par tdk007 dans le forum Windows Forms
    Réponses: 1
    Dernier message: 06/06/2008, 07h14
  2. Réponses: 2
    Dernier message: 27/05/2008, 08h42
  3. The data "null" is not legal for a JDOM attribute
    Par Smix007 dans le forum JDBC
    Réponses: 7
    Dernier message: 04/04/2008, 17h18
  4. Réponses: 1
    Dernier message: 12/11/2007, 15h48
  5. inside the data
    Par foblar dans le forum MS SQL Server
    Réponses: 10
    Dernier message: 28/07/2006, 09h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo