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

VC++ .NET Discussion :

securit� sous visual c++


Sujet :

VC++ .NET

  1. #61
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    non c pas sur vista ...c sur windows xp

  2. #62
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    j'ai recommenc� un autre projet(ca marche tjrs pas ) avec une seule form o� l utilisateur rentre son fichier (� crypter) et son mon de passe qui va servir pour crypter
    une fois il clik sur ok le fichier sera crypt�
    voici mon code ...
    Fichiers attach�s Fichiers attach�s

  3. #63
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    il me met comme erreur dans le aes.cpp

    API call 'ImportFile' failed :le systeme ne peut pas trouver "stdafx.h"

  4. #64
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    maintenant j'ai les methodes crypter et decrypter et generate key directement dans ma form1 pour que je puisse utiliser sans probl�mes

    voici le code de la form1:

    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
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
     
    #pragma once
     
     
    namespace crypt_file {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
     
                 using namespace System::Text;
                 using namespace System::Security::Cryptography;
                 using namespace System::IO;
     
    	/// <summary>
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the
    	///          'Resource File Name' property for the managed resource compiler tool
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
     
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    	private: System::Windows::Forms::Label^  label1;
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::TextBox^  textBox2;
    	private: System::Windows::Forms::Label^  label2;
     
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    			this->label2 = (gcnew System::Windows::Forms::Label());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(103, 225);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(79, 25);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"OK";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Location = System::Drawing::Point(53, 55);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(20, 13);
    			this->label1->TabIndex = 1;
    			this->label1->Text = L"file";
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(56, 162);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(170, 20);
    			this->textBox1->TabIndex = 2;
    			// 
    			// textBox2
    			// 
    			this->textBox2->Location = System::Drawing::Point(56, 81);
    			this->textBox2->Name = L"textBox2";
    			this->textBox2->Size = System::Drawing::Size(170, 20);
    			this->textBox2->TabIndex = 3;
    			// 
    			// label2
    			// 
    			this->label2->AutoSize = true;
    			this->label2->Location = System::Drawing::Point(53, 122);
    			this->label2->Name = L"label2";
    			this->label2->Size = System::Drawing::Size(29, 13);
    			this->label2->TabIndex = 4;
    			this->label2->Text = L"pass";
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 270);
    			this->Controls->Add(this->label2);
    			this->Controls->Add(this->textBox2);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    #pragma endregion
    	private : String ^val1;
    	private : String ^val2;
    	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
     
    				 val1 = "Saisir un pass ...";
    				 val2 = "Saisir un fichier";
    				 textBox1->Text = val1;
    				 textBox2->Text = val2;
    			 }
     
     
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
     
    			 StreamReader ^sr = gcnew StreamReader(this->GetValue2());
    			 StreamWriter ^sw = gcnew StreamWriter("Desktop\text0.doc");
     
    				 try
    	{
    		String ^a = Crypter(sr->ReadToEnd(), this->GetValue1());
    		sw->Write(a);
    	}
    	catch (Exception^)
    	{
    	}
    	finally
    	{
    		sr->Close();
    		sw->Close();
    	}
     
     
    		 }
     public:
    		String ^GetValue1()
    		{
    			return val1;
    		}
    public:
    		String ^GetValue2()
    		{
    			return val2;
    		}
     
    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);
    }
     
     
    };
    }
    il me mets exception : Could not find file 'h:\Data\Visual Studio 2005\Projects\crypt_file\crypt_file\Saisir un fichier'.
    en fait il prend pas en compte ce que l utilisateur a rentrer, il cherche le fichier 'h:\Data\Visual Studio 2005\Projects\crypt_file\crypt_file\Saisir un fichier'.

  5. #65
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut erreur :Illegal characters in path
    en fait il prend en compte que les fichiers existents dans le repertoire du projet
    je lui ai rentr� le fichier :
    D:\Data\Visual Studio 2005\Projects\crypt_file\crypt_file\test.txt

    il me met une autre erreur :
    An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

    Additional information: Illegal characters in path.

    est ce que quelqu'un a une id�e comment on resoud cette erreur ??

    merci

  6. #66
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    il faut doubler les \ dans une chaine

  7. #67
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    merci..en fait je veux utiliser un algorithme � cl� publique au lieu du AES (que vous m'avez donn�) est ce que vous avez un code pour crypter des fichiers utilisant un algorithme � cl� publique (RSA ou DSA )?
    merci beaucoups

  8. #68
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    en fait par rapport au code de cryptage et decryptage avec l'algorithme aes:

    si je prend un fichier test.txt je le crypt puis decrypt pour avoir test0.txt
    normalement test.txt et test0.txt doivent �tre identiques ??
    pourquoi test0.txt et test.txt n'ont pas la m�me taille ?

    j'ai test� aussi de crypter un fichier zip(mais en changeant son extension en .txt) je l ai crypt� et decrypt� je le re-extrais ca marche pas , il m'affiche fichier corrompu !

    est ce que t'as une id�e comment je pourrais utiliser l'algorithme aes pour crypter et decrypter des fichiers de n'importe quelle autre type?

  9. #69
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    l'exemple que je t'ai donn� avec rindjael fonctionne tr�s bien, j'ai test�
    ca te suffit pas ?

  10. #70
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    je l'ai utilis� mais il encrypte et decrypte que des fichiers text.
    j'ai test� avec un fichier zip : prend par exemple un fichier test.zip crypte le et decrypte le ca te donnera par exemple un fichier test1.zip si tu veux extraire ce fichier test1.zip ca te donnera fichier corrompu !(j'ai test� aussi pour un fichier .doc ca marche pas non plus!)
    est ce que tu as id�e pour pouvoir utiliser l algo rijndael pour tous les types de fichiers (.zip .doc ..)?

  11. #71
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut crypter et decrypter tous les types de fichiers (.doc, .zip..rar...))
    Bonjour,
    En fait ca marche que pour les fichiers .txt, si tu essaie pour les autres types de fichiers (.doc, .rar, .zip ) ca marche pas !
    donc je crois que si on change les m�thodes crypter et decrypter de telle sorte qu'elle donne des chaines de caract�res au lieu de string peut etre ca marchera ...
    j'ai essay� mais ca me donne un fichier decrypt� vide

    est ce que t a une id�e comment utiliser le code que tu m'a donn� pour crypter et decrypter tous les types de fichiers ?
    merci

  12. #72
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    c'est parce qu'il faut utiliser un stream binaire

  13. #73
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    je te l'ai fait ...
    � tout hasard

    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
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
     
    using namespace System;
    using namespace System::Text;
    using namespace System::Security::Cryptography;
    using namespace System::IO;
     
     
    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];
    }
     
    array<unsigned char> ^ Crypter(array<unsigned char> ^encrypted, 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();
     
        myRijndael->Key = Key;
        myRijndael->IV = IV;
     
        ICryptoTransform ^encryptor = myRijndael->CreateEncryptor(Key, IV);
        MemoryStream ^msEncrypt = gcnew MemoryStream();
    	CryptoStream ^csEncrypt = gcnew CryptoStream(msEncrypt, encryptor, CryptoStreamMode::Write);
     
        csEncrypt->Write(encrypted, 0, encrypted->Length);
        csEncrypt->FlushFinalBlock();
     
        encrypted = msEncrypt->ToArray();
    	return encrypted;
    }
     
    array<unsigned char> ^ Decrypter(array<unsigned char> ^encrypted, 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> ^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 = gcnew array<unsigned char>(encrypted->Length);
     
        csDecrypt->Read(fromEncrypt, 0, fromEncrypt->Length);
     
    	return fromEncrypt;
    }
     
     
    int main(array<System::String ^> ^args)
    {
    	FileStream ^fs = gcnew FileStream("c:\\test.zip", FileMode::Open);
    	BinaryReader ^br = gcnew BinaryReader(fs);
    	FileStream ^fsw = gcnew FileStream("c:\\test.cry", FileMode::CreateNew);
    	BinaryWriter ^bw = gcnew BinaryWriter(fsw);
    	try
    	{
    		bw->Write(Crypter(br->ReadBytes((int)fs->Length), "code secret"));
    	}
    	catch (Exception^)
    	{
    	}
    	finally
    	{
    		br->Close();
    		fs->Close();
    		bw->Close();
    		fsw->Close();
    	}
    	fs = gcnew FileStream("c:\\test.cry", FileMode::Open);
    	br = gcnew BinaryReader(fs);
    	fsw = gcnew FileStream("c:\\test2.zip", FileMode::CreateNew);
    	bw = gcnew BinaryWriter(fsw);
    	try
    	{
    		bw->Write(Decrypter(br->ReadBytes((int)fs->Length), "code secret"));
    	}
    	catch (Exception^)
    	{
    	}
    	finally
    	{
    		br->Close();
    		fs->Close();
    		bw->Close();
    		fsw->Close();
    	}
        return 0;
    }

  14. #74
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    merci beaucoups

    En fait j'aimerais utiliser un algorithme � cl� publique (RSA ou DSA) pour pouvoir l'utiliser pour crypter le mot de passe (le code secret) qui sert � crypter et decrypter les fichiers avec Rijndael

    est ce que t'as un code pour RSA ?

    merci d'avance

  15. #75
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414

  16. #76
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut compression/decompression
    j y suis d�ja all� ..mais j'ai pas reussi
    une autre question je veux aussi compresser des fichiers donc j'ai utilis� le code de cet faq :
    http://dotnet.developpez.com/faq/cpp...ge=compression
    mais ca n'a pas march� il m'affiche beaucoups d'erreurs, donc je me suis inspir� du code de rijndael que tu m'a donn�, voici mon 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
     
     public:
    	  array<unsigned char> ^compressFile(array<unsigned char> ^compressed)
    {
         MemoryStream ^mscompress = gcnew MemoryStream();
    	GZipStream ^gscompress = gcnew GZipStream(mscompress, CompressionMode::Compress,false);
     
        gscompress->Write(compressed, 0, compressed->Length);
    //    gscompress->FlushFinalBlock();
     
        compressed = mscompress->ToArray();
    	return compressed; 
    }
    int main(array<System::String ^> ^args)
    {
      FileStream ^fs = gcnew FileStream("C:\\test.txt", FileMode::Open);
    			 BinaryReader ^br = gcnew BinaryReader(fs);
    			 FileStream ^fsw = gcnew FileStream("C:\\testcomp.gz",FileMode::CreateNew);
    			 BinaryWriter ^bw = gcnew BinaryWriter(fsw);
     
    			 try
    			 {
    				 bw->Write(compressFile(br->ReadBytes((int)fs->Length)));
    			 }
    			 catch (Exception^)
    			 {
    			 }
    			 finally
    			 {
    				 br->Close();
    		         fs->Close();
    		         bw->Close();
    		         fsw->Close();
    			 }
     
    	    return 0;
    }
    __________________
    ca me genere un fichier C:\\testcomp.gz mais quand je veuy l ouvrir il m'affiche une erreurs
    est ce que tu pourrais jeter un coup d'oeil sur ce code et me dire ce qui va pas stp ?

    merci d avance

  17. #77
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    le code de la faq fonctionne

  18. #78
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut
    je l ai test� ca marche pas
    ca me genere des erreurs

    est ce que tu peux voir le code que j'ai fait et voir est ce qui cloche stp?
    je me suis inspir� du code de la faq et du code de rijndal que tu m a donn�

    parce que j ai remarqu� que dans le code de rijendal c�st dans le main que tu fais le try alors que dans le code de la faq non et parce que le code rijndael ca marche bien chez moi!

    merci

  19. #79
    Membre �clair�
    Inscrit en
    Avril 2007
    Messages
    326
    D�tails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Par d�faut code de compression en fichier .zp
    en fait le code de la faq ne marche po !je l 'ai essay� ca veut pas marcher
    par contre le code que tu m a donn� (Rijndael)marche !
    donc je me suis dit que je vais m'inspirer du code de la faq et faire une fonction comress avec un main (comme le code de rijndael)
    voici le 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
     
      array<unsigned char> ^compressFile(array<unsigned char> ^compressed)
    {
         MemoryStream ^mscompress = gcnew MemoryStream();
    	GZipStream ^gscompress = gcnew GZipStream(mscompress, CompressionMode::Compress,false);
     
        gscompress->Write(compressed, 0, compressed->Length);
    //    gscompress->FlushFinalBlock();
     
        compressed = mscompress->ToArray();
    	return compressed; 
    }
    int main(array<System::String ^> ^args)
    {
      FileStream ^fs = gcnew FileStream("C:\\test.txt", FileMode::Open);
    			 BinaryReader ^br = gcnew BinaryReader(fs);
    			 FileStream ^fsw = gcnew FileStream("C:\\testcomp.gz",FileMode::CreateNew);
    			 BinaryWriter ^bw = gcnew BinaryWriter(fsw);
     
    			 try
    			 {
    				 bw->Write(compressFile(br->ReadBytes((int)fs->Length)));
    			 }
    			 catch (Exception^)
    			 {
    			 }
    			 finally
    			 {
    				 br->Close();
    		         fs->Close();
    		         bw->Close();
    		         fsw->Close();
    			 }
     
    	    return 0;
    }
    ca marche mais ca me genere un fichier .zp mais ke j arrive po a ouvrir (de taille 0 ko)
    est ce que tu peux regarder stp ?

    merci

  20. #80
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    je ne suis pas sur de comprendre
    tu cherches � compresser un fichier encod� ?

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. [MSChart] creation de courbe sous visual C++
    Par gabriel knight dans le forum MFC
    R�ponses: 5
    Dernier message: 18/09/2006, 14h32
  2. Impression sous visual c++
    Par zeze511 dans le forum MFC
    R�ponses: 2
    Dernier message: 16/02/2004, 12h02
  3. probl�me de compilation sous visual C++
    Par fabmili dans le forum MFC
    R�ponses: 4
    Dernier message: 08/02/2004, 19h52
  4. R�ponses: 3
    Dernier message: 28/01/2004, 10h46
  5. Deplacer un curseur dans un RichEdit sous visual c
    Par tweek dans le forum Windows
    R�ponses: 7
    Dernier message: 14/01/2004, 00h29

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