Crypter/decrypter des fichier(tous les types)

ryoussef1983 Messages postés 14 Date d'inscription lundi 19 mars 2007 Statut Membre Dernière intervention 13 juin 2007 - 9 mai 2007 à 14:36
Dsantu Messages postés 2 Date d'inscription lundi 4 juin 2007 Statut Membre Dernière intervention 16 juillet 2007 - 16 juil. 2007 à 11:38
En fait j'utilise visual studio 2005 (sous visual c++)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /??>





j'ai réussi à trouver des méthodes pour crypter et décrypter mais le problème est que ca ne crypte que des fichiers txt .
ca peut crypter d'autres types de fichiers par exemole un test.zip, mais si je le crypte et je le decrypte j'aurais par exemple un fichier test1.zip
ce fichier quand je veux l'ouvrir il me dit fichier corrompu!

<?xml:namespace prefix v ns "urn:schemas-microsoft-com:vml" /??>
<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600">
<v:stroke joinstyle="miter">
</v:stroke>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
</v:f>
<v:f eqn="sum @0 1 0">
</v:f>
<v:f eqn="sum 0 0 @1">
</v:f>
<v:f eqn="prod @2 1 2">
</v:f>
<v:f eqn="prod @3 21600 pixelWidth">
</v:f>
<v:f eqn="prod @3 21600 pixelHeight">
</v:f>
<v:f eqn="sum @0 0 1">
</v:f>
<v:f eqn="prod @6 1 2">
</v:f>
<v:f eqn="prod @7 21600 pixelWidth">
</v:f>
<v:f eqn="sum @8 21600 0">
</v:f>
<v:f eqn="prod @7 21600 pixelHeight">
</v:f>
<v:f eqn="sum @10 21600 0">
</v:f>
</v:formulas>
<v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f">
</v:path>
<o:lock aspectratio="t" v:ext="edit">
</o:lock>
</v:shapetype>
<v:shape id="_x0000_i1025" style="WIDTH: 11.25pt; HEIGHT: 11.25pt" type="#_x0000_t75" alt="">
<v:imagedata o:href="http://www.cppfrance.com/imgs2/smile_dissapprove.gif" src="file:///C:\DOKUME~1\ERAMAHY\LOKALE~1\Temp\msohtml1\01\clip_image001.gif">
</v:imagedata>
</v:shape>









est ce que quelqu'un a  une idée pour pouvoir crypter et  decrypter tout genre de fichier

<v:shape id="_x0000_i1026" style="WIDTH: 11.25pt; HEIGHT: 11.25pt" type="#_x0000_t75" alt="">
<v:imagedata o:href="http://www.cppfrance.com/imgs2/smile_question.gif" src="file:///C:\DOKUME~1\ERAMAHY\LOKALE~1\Temp\msohtml1\01\clip_image002.gif">
</v:imagedata>
</v:shape>
<v:shape id="_x0000_i1027" style="WIDTH: 11.25pt; HEIGHT: 11.25pt" type="#_x0000_t75" alt="">
<v:imagedata o:href="http://www.cppfrance.com/imgs2/smile_question.gif" src="file:///C:\DOKUME~1\ERAMAHY\LOKALE~1\Temp\msohtml1\01\clip_image002.gif">
</v:imagedata>
</v:shape>



voici le code:





public





:





void


GenerateKey(String ^SecretPhrase,
array


<


unsigned


char


> ^&Key,
array


<


unsigned


char


> ^&IV)





{





array


<


unsigned


char


> ^bytePhrase = Encoding::ASCII->GetBytes(SecretPhrase);





SHA384Managed ^sha384 = gcnew SHA384Managed();








sha384->ComputeHash(bytePhrase);





array


<


unsigned


char


> ^result = sha384->Hash;





for


(


int


loop = 0; loop < 24; loop++)





Key[loop] = result[loop];





for


(


int


loop = 24; loop < 40; loop++)





IV[loop - 24] = result[loop];





}





public





:





String ^ Crypter(String ^original, String ^keyPhrase)





{





array


<


unsigned


char


> ^Key =
gcnew


array


<


unsigned


char


>(24);





array


<


unsigned


char


> ^IV =
gcnew


array


<


unsigned


char


>(16);





GenerateKey(keyPhrase, Key, IV);





ASCIIEncoding ^textConverter = gcnew ASCIIEncoding();








RijndaelManaged ^myRijndael = gcnew RijndaelManaged();








array


<


unsigned


char


> ^encrypted;





array


<


unsigned


char


> ^toEncrypt;





myRijndael->Key = Key;





myRijndael->IV = IV;





ICryptoTransform ^encryptor = myRijndael->CreateEncryptor(Key, IV);





MemoryStream ^msEncrypt = gcnew MemoryStream();








CryptoStream ^csEncrypt = gcnew CryptoStream(msEncrypt, encryptor, CryptoStreamMode::Write);








toEncrypt = textConverter->GetBytes(original);





csEncrypt->Write(toEncrypt, 0, toEncrypt->Length);





csEncrypt->FlushFinalBlock();





encrypted = msEncrypt->ToArray();





return


Convert::ToBase64String(encrypted);





}





public


:





String ^ Decrypter(String ^ encryptedString, String ^keyPhrase)





{





array


<


unsigned


char


> ^Key =
gcnew


array


<


unsigned


char


>(24);





array


<


unsigned


char


> ^IV =
gcnew


array


<


unsigned


char


>(16);





GenerateKey(keyPhrase, Key, IV);





array


<


unsigned


char


> ^encrypted = Convert::FromBase64String(encryptedString);





array


<


unsigned


char


> ^fromEncrypt;





RijndaelManaged ^myRijndael =





gcnew


RijndaelManaged();





ASCIIEncoding ^textConverter =





gcnew


ASCIIEncoding();





myRijndael->Key = Key;





myRijndael->IV = IV;





ICryptoTransform ^decryptor = myRijndael->CreateDecryptor(Key, IV);





MemoryStream ^msDecrypt = gcnew MemoryStream(encrypted);








CryptoStream ^csDecrypt = gcnew CryptoStream(msDecrypt, decryptor, CryptoStreamMode::Read);








fromEncrypt = gcnewarray < unsignedchar >(encrypted->Length);








csDecrypt->Read(fromEncrypt, 0, fromEncrypt->Length);





return


textConverter->GetString(fromEncrypt);





}





int main( array <System::String ^> ^args){









 






StreamReader ^sr = gcnew StreamReader( this ->val3);








StreamWriter ^sw = gcnew StreamWriter( this ->val5);








try










{





String ^a = Crypter(sr->ReadToEnd(), this ->GetValue1());








sw->Write(a);





}





catch


(Exception^)





{





}





finally










{





sr->Close();





sw->Close();





}





StreamReader ^sr = gcnew StreamReader( this ->val3);








StreamWriter ^sw = gcnew StreamWriter( this ->val5);








try










{





String ^a = Decrypter(sr->ReadToEnd(), this ->GetValue1());








sw->Write(a);





}





catch


(Exception^)





{





}





finally










{





sr->Close();





sw->Close();





}
return0;
}

5 réponses

emmatopiak Messages postés 149 Date d'inscription mercredi 28 mars 2007 Statut Membre Dernière intervention 17 mai 2007 2
9 mai 2007 à 15:15
Tu vas con tinuer a flooder comme ça combien de temps ? Ca fait trois fois que tu post le même, on t'a répondu dans les autres, alors regarde stp tes autres topics!

Une autruche ne se cuit pas aux petits lardons.
0
ryoussef1983 Messages postés 14 Date d'inscription lundi 19 mars 2007 Statut Membre Dernière intervention 13 juin 2007
9 mai 2007 à 15:35
c par ce que dans l'aute le code etait pas lisible
donc je me suis dis je vais reposer la meme question en plus lisible
dsl..
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
9 mai 2007 à 22:12
No problem tout va bon, j'ai enlevé le post précédent.

ciao...
BruNews, MVP VC++
0
ryoussef1983 Messages postés 14 Date d'inscription lundi 19 mars 2007 Statut Membre Dernière intervention 13 juin 2007
10 mai 2007 à 09:09
j'ai changé les methodes crypter et decrypter de facon à ce que ca donne des array (à la place des strings), cette fois ci ca me donne un fichier vide lorsque je decrypte ?

est ce que t a une idée comment je pourrais utiliser des tableaux de caractères à la place des string
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Dsantu Messages postés 2 Date d'inscription lundi 4 juin 2007 Statut Membre Dernière intervention 16 juillet 2007
16 juil. 2007 à 11:38
Bonjour

Je cherche de l'aide à propos des générateurs peudo aléatoires.


Je veux programmer un Galois_LFSR en C/C++ mais je n'arrive pas a avoir des résultats coérents.


Quelqu'un peut-'il me donner un algo de codage deGalois-LFSR en utilisant des tableaux comme registre?


Merci
0
Rejoignez-nous