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 :

cryptage avec RSA sous visual C++


Sujet :

VC++ .NET

  1. #1
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut cryptage avec RSA sous visual C++
    Citation Envoyé par nico-pyright(c)
    c'est pas si compliqué que ca ...
    le seul truc un peu délicat, c'est la génération des clés publiques et privées, si tu as besoin de les sauver
    voila pour l'instant j'ai reussi à générer deux fichiers le premier pour la clé privé et l'autre pour la clé privé
    mais reste les fonctions qui crypte et decrypte, voici mon code pour la fonction qui crypte
    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
     
    array<Byte>^ RSAEncrypt( array<Byte>^DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding )
    {
          RSACryptoServiceProvider^ RSA = gcnew RSACryptoServiceProvider;
     
     
          RSA->ImportParameters( RSAKeyInfo );
     
     
          return RSA->Encrypt( DataToEncrypt, DoOAEPPadding );
    }
     
    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:\\test1.txt",FileMode::CreateNew);
    			 BinaryWriter ^bw = gcnew BinaryWriter(fsw);
     
     
    			 try
       {
     
     
    	  array<Byte>^dataToEncrypt = br->ReadBytes((int)fs->Length 
          array<Byte>^encryptedData;
          array<Byte>^decryptedData;
     
     
          RSACryptoServiceProvider^ RSA = gcnew RSACryptoServiceProvider;
     
          encryptedData = RSAEncrypt( dataToEncrypt, RSA->ExportParameters( false ), false );
    	  bw->Write(encryptedData);
    			 }
    			    catch ( Exception^ ) 
    				 {
    				 }
    				finally
    				{
    					br->Close();
    					fs->Close();
    					bw->Close();
    					fsw->Close();
    				}
     
    		 }
        return 0;
    }
    il me genere un fichier vide
    et je ne sais pas comment faire pour utiliser la clé génerée(sauvegardée)?
    est ce que tu peux voir ce code et me dire ce qui ne va pas ?
    merci

  2. #2
    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
    Points : 16 075
    Points
    16 075
    Par défaut
    bon ...

    regarde cet exemple simpliste, mais cherche un peu !
    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
    using namespace System;
    using namespace System::IO;
    using namespace System::Security::Cryptography;
     
    void genererCle(String ^fichierPublicPrivee, String ^fichierClePublic)
    {
    	if (!(File::Exists(fichierPublicPrivee) || File::Exists(fichierClePublic)) )
    	{
    		RSACryptoServiceProvider ^rsaProvider = gcnew RSACryptoServiceProvider(1024);
    		String ^clesPublicEtPrivee = rsaProvider->ToXmlString(true);
    		String ^clePublic = rsaProvider->ToXmlString(false);
    		StreamWriter ^sw = gcnew StreamWriter(fichierPublicPrivee);
    		sw->Write(clesPublicEtPrivee);
    		sw->Close();
    		sw = gcnew StreamWriter(fichierClePublic);
    		sw->Write(clePublic);
    		sw->Close();
    	}
    	else
    		Console::WriteLine("fichier de clés existant");
    }
     
    array<unsigned char> ^ encrypt(String ^fichierClePublic, array<unsigned char> ^data)
    {
    	StreamReader ^sr = gcnew StreamReader(fichierClePublic);
    	String ^cle = sr->ReadLine();
    	sr->Close();
    	RSACryptoServiceProvider ^rsaProvider = gcnew RSACryptoServiceProvider(1024);
    	rsaProvider->FromXmlString(cle);
    	return rsaProvider->Encrypt(data, false);
    }
     
    array<unsigned char> ^ decrypt(String ^fichierPublicPrivee, array<unsigned char> ^data)
    {
    	StreamReader ^sr = gcnew StreamReader(fichierPublicPrivee);
    	String ^cle = sr->ReadLine();
    	sr->Close();
    	RSACryptoServiceProvider ^rsaProvider = gcnew RSACryptoServiceProvider(1024);
    	rsaProvider->FromXmlString(cle);
    	return rsaProvider->Decrypt(data, false);
    }
     
    int main(array<System::String ^> ^args)
    {
        genererCle("pp", "p");
    	String ^ chaine = "chaine à encoder";
    	array<unsigned char> ^ encrypted = encrypt("p", Text::Encoding::Unicode->GetBytes(chaine));
    	array<unsigned char> ^ decrypted = decrypt("pp", encrypted);
    	String ^chaineDecodee = Text::Encoding::Unicode->GetString(decrypted);
    	Console::WriteLine(chaineDecodee);
        return 0;
    }

  3. #3
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    ok..merci
    le "p" et le "pp" correspondent aux 2 fichiers de clé publique et privé c'est ca ?
    donc je peux mettre à leur place les fichiers que j'ai reussi à génerer ?

  4. #4
    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
    Points : 16 075
    Points
    16 075
    Par défaut
    oui

  5. #5
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut System.Security.Cryptography.CryptographicException
    ce que je veux c'est crypter et decrypter des fichiers ..donc j'ai changé dans le main de ton code , de facon à ce que je puisse crypter le fichier "c:\\test.txt" en "c:\\test1.txt" et le decrypter après en "c:\\test2.txt"
    mais il me genere une exception
    "System.Security.Cryptography.CryptographicException"

    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
    37
    38
    39
     
    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:\\test1.txt",FileMode::CreateNew);
    BinaryWriter ^bw = gcnew BinaryWriter(fsw);
    genererCle("pp", "p");
     
    	array<unsigned char> ^ encrypted = 
    encrypt("p", br->ReadBytes((int)fs->Length));
    	bw->Write(encrypted);
     
    			   br->Close();
    		         fs->Close();
    		         bw->Close();
    		         fsw->Close();
     
    FileStream ^fs = gcnew FileStream("c:\\test1.txt", FileMode::Open);
    BinaryReader ^br = gcnew BinaryReader(fs);
    FileStream ^fsw = gcnew FileStream("c:\\test2.txt",FileMode::CreateNew);
    BinaryWriter ^bw = gcnew BinaryWriter(fsw);
     
     
     
     
     
     
    	array<unsigned char> ^ decrypted = decrypt("pp", encrypted);
    	bw->Write(decrypted);
    			   br->Close();
    		         fs->Close();
    		         bw->Close();
    		         fsw->Close();
     
    return0;
    }

  6. #6
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    ce que je veux c'est crypter et decrypter des fichiers ..donc j'ai changé dans le main de ton code , de facon à ce que je puisse crypter le fichier "c:\\test.txt" en "c:\\test1.txt" et le decrypter après en "c:\\test2.txt"
    mtnt je n'ai plus cette exception .. mais il me genere un fichier ("c:\\test1.txt" ) vide
    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
     
     
    int main(array<System::String ^> ^args)
    {
     
     genererCle("pp", "p");
    	FileStream ^fs = gcnew FileStream("c:\\test.txt", FileMode::Open);
    	BinaryReader ^br = gcnew BinaryReader(fs);
    	FileStream ^fsw = gcnew FileStream("c:\\test1.txt", FileMode::CreateNew);
    	BinaryWriter ^bw = gcnew BinaryWriter(fsw);
    	try
    	{
    		array<unsigned char> ^ encrypted = encrypt("p", br->ReadBytes((int)fs->Length));
    		bw->Write(encrypted);
    	}
    	catch (Exception^)
    	{
    	}
    	finally
    	{
    		br->Close();
    		fs->Close();
    		bw->Close();
    		fsw->Close();
    	}
    return 0;
    }

  7. #7
    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
    Points : 16 075
    Points
    16 075
    Par défaut
    l'encryption et la décryption doit se faire avec taille limitée, il faut donc boucler x fois

  8. #8
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    ca veut dire si je crypte un fichier de taille petite ca va marcher ??
    et comment je peux boucler ?
    est ce que tu peux détailler un peu plus

    d'ailleurs j'ai essayé de crypter un fichier texte et ca marche pas non plus (ca me genere un fichier vide )

  9. #9
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut chaine cryptée vide
    l'encryption et la décryption doit se faire avec taille limitée, il faut donc boucler x fois
    maintenant, j'ai essayé de crypter juste la chaine "chaine à encoder" et mettre sa valeur cryptée (avec ma clé publique "test.pke") dans le un fichier c:\test1.txt
    mais ca continue à me donner un fichier vide ..donc je crois pas que le problème vient de la taille
    voici mon main :
    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
     
     
    int main(array<System::String ^> ^args)
    {
                  StreamWriter ^sw =gcnew StreamWriter("c:\\test1.txt");
    try
    {
        	String ^ chaine = "chaine à encoder";
    	sw->Write(encrypt("c:\\test.pke", System::Text::Encoding::Unicode->GetBytes(chaine)));    
    }
    catch(Exception^)
    {
    }
    finally
    {
     
    sw->Close();
    }
    return 0;
    }

  10. #10
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    voila ton exemple marche bien
    mais quand je change dans le main :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    encrypt("p", Text::Encoding::Unicode->GetBytes(chaine));
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    encrypt("c:\\test.pke", Text::Encoding::Unicode->GetBytes(chaine));
    ca marche pas !!!
    sachant que ce fichier : "c:\\test.pke" est un fichier clé publique que j'ai déjà généré et sauver !

    est ce que t'as une idée pourquoi ca marche pas??

    merci d'avance

  11. #11
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    j'ai reussi à le faire
    mtnt j'utilise les fichiers .pke(clé publique) et .kez(clé privée ) que j'ai déja generé
    mais reste un probleme

    ca marche quand je mets directement dans le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     StreamReader ^sr = gcnew StreamReader("c:\\test.pke");
    mais quand je mets à la place
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    StreamReader ^sr = gcnew StreamReader(textBox1->text->replace("\\","\\\\"));
    c'est à dire je donne le choix à l'utilisateur de choisir son fichier clé publique
    il me genere cette exception:

    An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll

    Additional information: Input string does not contain a valid encoding of the 'RSA' 'Modulus' parameter.

  12. #12
    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
    Points : 16 075
    Points
    16 075
    Par défaut
    c'est pas la peine de remplacer les \ par \\, c'est uniquement quand tu l'écris en dur dans le code
    quand c'est dans une variable, c'est inutile

  13. #13
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    je crois ce n'est pas ca le pb

    quand je choisis ds ma forme les clés que j'ai déjà généré .. c'est lÀ où ca plante ..parce que il me crée deux autres clés "p" et "pp"

    je t'ai joint le code de ma form1 ..est ce que tu peux y jeter un coup d oeil stp ?

    merci d'avance
    Fichiers attachés Fichiers attachés

  14. #14
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    en fait j'ai remarqué qu'il n'utilise pas les fichiers de clé que je genere ..puisque je les ai pas généré pourtant ca crypte et decrypte !

  15. #15
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    je crois que j'ai compris
    les fichier clé publique et clé privée existent déja donc ds la fct genererclé il passe direct dans le esle (fichier clé existents!)

    mtnt j'ai enlevé le if et le else et j'ai mis directement :

    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
     
    //if (!(File::Exists(fichierPublicPrivee) || File::Exists(fichierClePublic)) )
    	//{
    		//RSACryptoServiceProvider ^rsaProvider = gcnew RSACryptoServiceProvider(1024);
    		//String ^clesPublicEtPrivee = rsaProvider->ToXmlString(true);
    		//String ^clePublic = rsaProvider->ToXmlString(false);
     
    						 StreamReader ^sr = gcnew StreamReader("c:\\test.pke");
    		StreamWriter ^sw = gcnew StreamWriter(fichierPublicPrivee);
    		sw->Write(sr->ReadLine());
    		sr->Close();
    		sw->Close();
     
    		StreamReader ^sr1 = gcnew StreamReader("c:\\test.kez");
    		sw = gcnew StreamWriter(fichierClePublic);
    		sw->Write(sr1->ReadLine());
    		sw->Close();
    		sr1->Close();
    	//}
    	//else
    		//Console::WriteLine("fichier de clés existant");
    }
    il me genere une exception :

    An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll

    Additional information: Input string does not contain a valid encoding of the 'RSA' 'Modulus' parameter.

    donc je comprend pas pourquoi il ne prend pas en compte mes fichiers clés ??

  16. #16
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut help!
    Citation Envoyé par nico-pyright(c)
    l'encryption et la décryption doit se faire avec taille limitée, il faut donc boucler x fois
    j'ai tt essayer ...
    est ce que tu peux présicer stp comment je pourrais boucler ?
    est ce que je dois decrypter block par block
    mais le probleme est que quand je decrypte par exemple les 128 bytes premiers il m'affiche "données invalides"
    autre question :
    quand je passe pas par un fichier c'est à dire ce encrypted je le mets dans un val et je decrypt le val ca marche il n y a pas de pb de taille
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    array<unsigned char> ^ encrypted = encrypt( System::Text::Encoding::Unicode->GetBytes(chaine));
    		String ^chaineencodee = System::Text::Encoding::Unicode->GetString(encrypted);
    		val=encrypted;
    		sw->Write(chaineencodee);
    array<unsigned char> ^ decrypted = decrypt(val);
    par contre si je mets ce encrypted dans un fichier (c:\test1.txt)puis je le recupere puis je decrypte le val n'a pas la meme taille (plus grand qu'avant) et ca marche pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    array<unsigned char> ^ encrypted = encrypt( System::Text::Encoding::Unicode->GetBytes(chaine));
    		String ^chaineencodee = System::Text::Encoding::Unicode->GetString(encrypted);
    		//val=encrypted;
    FileStream ^fs = gcnew FileStream("c:\\test1.txt", FileMode::Open);
    			 BinaryReader ^br = gcnew BinaryReader(fs);
     
    			 arrayLength = (fs->Length);
     
    			 val=br->ReadBytes(arrayLength);
     
    array<unsigned char> ^ decrypted = decrypt(val);
    fs->Close();
    br->Close();

  17. #17
    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
    Points : 16 075
    Points
    16 075
    Par défaut
    bon, je t'ai fait un petit exemple :
    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
     
    using namespace System;
    using namespace System::Text;
    using namespace System::IO;
    using namespace System::Collections::Generic;
    using namespace System::Security::Cryptography;
     
    void genererCle(String ^fichierPublicPrivee, String ^fichierClePublic)
    {
    	if (!(File::Exists(fichierPublicPrivee) || File::Exists(fichierClePublic)) )
    	{
    		RSACryptoServiceProvider ^rsaProvider = gcnew RSACryptoServiceProvider(1024);
    		String ^clesPublicEtPrivee = rsaProvider->ToXmlString(true);
    		String ^clePublic = rsaProvider->ToXmlString(false);
    		StreamWriter ^sw = gcnew StreamWriter(fichierPublicPrivee);
    		sw->Write(clesPublicEtPrivee);
    		sw->Close();
    		sw = gcnew StreamWriter(fichierClePublic);
    		sw->Write(clePublic);
    		sw->Close();
    	}
    	else
    		Console::WriteLine("fichier de clés existant");
    }
     
    String ^ encryptString(String ^fichierClePublic, String ^data)
    {
    	StreamReader ^sr = gcnew StreamReader(fichierClePublic);
    	String ^cle = sr->ReadLine();
    	sr->Close();
     
    	RSACryptoServiceProvider ^rsaProvider = gcnew RSACryptoServiceProvider(1024);
    	rsaProvider->FromXmlString(cle);
     
    	int keySize = 1024 / 8;
     
    	array<unsigned char> ^bytes = Encoding::UTF32->GetBytes( data );
    	int maxLength = keySize - 42;
    	int dataLength = bytes->Length;
    	int iterations = dataLength / maxLength;
    	StringBuilder ^stringBuilder = gcnew StringBuilder();
    	for( int i = 0; i <= iterations; i++ )
    	{
    		array<unsigned char> ^ tempBytes = gcnew array<unsigned char> (( dataLength - maxLength * i > maxLength ) ? maxLength : dataLength - maxLength * i);
    		Buffer::BlockCopy( bytes, maxLength * i, tempBytes, 0, tempBytes->Length );
    		array<unsigned char> ^ encryptedBytes = rsaProvider->Encrypt( tempBytes, true );
    		Array::Reverse( encryptedBytes );
    		stringBuilder->Append( Convert::ToBase64String( encryptedBytes ) );				
    	}			
    	return stringBuilder->ToString();
    }
     
    String ^DecryptString( String ^fichierClePublic, String ^inputString)
    {
    	StreamReader ^sr = gcnew StreamReader(fichierClePublic);
    	String ^cle = sr->ReadLine();
    	sr->Close();
     
    	RSACryptoServiceProvider ^rsaProvider = gcnew RSACryptoServiceProvider(1024);
    	rsaProvider->FromXmlString(cle);
    	int base64BlockSize = ( ( 1024 / 8 ) % 3 != 0 ) ? ( ( ( 1024 / 8 ) / 3 ) * 4 ) + 4 : ( ( 1024 / 8 ) / 3 ) * 4;
    	int iterations = inputString->Length / base64BlockSize;
    	List<unsigned char> ^list = gcnew List<unsigned char>();
    	for( int i = 0; i < iterations; i++ )
    	{
    		array<unsigned char> ^  encryptedBytes = Convert::FromBase64String( inputString->Substring( base64BlockSize * i, base64BlockSize ) );
    		Array::Reverse( encryptedBytes );
    		array<unsigned char> ^arr = rsaProvider->Decrypt( encryptedBytes, true );
    		for each(unsigned char c in arr)
    			list->Add(c);
    	}
    	return Encoding::UTF32->GetString(list->ToArray());
    }
     
     
    int main(array<System::String ^> ^args)
    {
        genererCle("pp", "p");
    	StreamReader ^sr = gcnew StreamReader("c:\\test.txt");
    	String ^ chaine = sr->ReadToEnd();
    	sr->Close();
    	String ^ encrypted = encryptString("p", chaine);
    	String ^ decrypted = DecryptString("pp", encrypted);
    	//String ^chaineDecodee = Text::Encoding::Unicode->GetString(decrypted);
    	Console::WriteLine(decrypted);
        return 0;
    }

  18. #18
    Membre du Club
    Inscrit en
    Avril 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 326
    Points : 62
    Points
    62
    Par défaut
    merci bien

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Creer un etat avec hierarchie sous Visual basic 6
    Par FRED-SUCCES dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 31/10/2009, 09h16
  2. Réponses: 2
    Dernier message: 02/11/2007, 17h44
  3. Réponses: 10
    Dernier message: 19/03/2007, 15h37
  4. Problème avec pminub sous Visual C++ 6
    Par Flo. dans le forum x86 32-bits / 64-bits
    Réponses: 5
    Dernier message: 06/10/2006, 10h14
  5. [debutant]opengl avec sdl sous visual c++
    Par bourinator dans le forum OpenGL
    Réponses: 1
    Dernier message: 13/06/2005, 11h24

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