Bonjour,

Voici une procédure permettant d'effectuer un chiffrement / déchiffrement RSA avec Windev.

J'utilise une dll RSA.dll (à télécharger ici : RSA.7z) que j'ai programmée en c# et dont voici le code :

Code c# : 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace RSA
{
    using System;
    using System.Security.Cryptography;
    using System.Text;
 
    public class RSATool
    {
 
        static public void GenerateKeys(ref string __publicPrivateKeyXML, ref string __publicOnlyKeyXML, ref string __sMessErr, int _ikeySize=1024)
        {
            try
            {
                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(_ikeySize);
                //Pair of public and private key as XML string. Do not share this to other party
                __publicPrivateKeyXML = RSA.ToXmlString(true);
                //Private key in xml file, this string should be share to other parties
                __publicOnlyKeyXML = RSA.ToXmlString(false);
            }
            catch (CryptographicException e)
            {
                __sMessErr = e.ToString();
            }
        }
 
        static public string RSAEncrypt(string _sDataToEncrypt, string _sPublicKeyXML, ref string __sMessErr, int _ikeySize=1024, bool DoOAEPPadding=true)
        {
            try
            {
                byte[] dataToEncrypt = Encoding.UTF8.GetBytes(_sDataToEncrypt);
                byte[] encryptedData;
 
                //Create a new instance of RSACryptoServiceProvider.
                using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(_ikeySize))
                {
                    RSA.FromXmlString(_sPublicKeyXML);
 
                    //Encrypt the passed byte array and specify OAEP padding. OAEP padding is only available on Microsoft Windows XP or later.  
                    encryptedData = RSA.Encrypt(dataToEncrypt, DoOAEPPadding);
                }
                return Convert.ToBase64String(encryptedData);
            }
            catch (CryptographicException e)
            {
                __sMessErr = e.ToString();
                return null;
            }
 
        }
 
        static public string RSADecrypt(string _sDataToDecryptBase64,string _sPrivateKeyXML, ref string __sMessErr, int _ikeySize=1024, bool DoOAEPPadding=true)
        {
            try
            {
                byte[] dataToDecrypt = Convert.FromBase64String(_sDataToDecryptBase64);
                byte[] decryptedBytes;
                string decryptedData;
 
                //Create a new instance of RSACryptoServiceProvider.
                using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(_ikeySize))
                {
                    RSA.FromXmlString(_sPrivateKeyXML);
 
                    //Decrypt the passed byte array and specify OAEP padding. OAEP padding is only available on Microsoft Windows XP or later.  
                    decryptedBytes = RSA.Decrypt(dataToDecrypt, DoOAEPPadding);
                    decryptedData = Encoding.UTF8.GetString(decryptedBytes);  
                }
                return decryptedData;
            }
            catch (CryptographicException e)
            {
                __sMessErr = e.ToString();
                return null;
            }
 
        }
    }
}

Pour utiliser la dll RSA.dll dans Windev, il faut tout d'abord l'extraire du répertoire compressé RSA.7z (avec l'utilitaire 7-Zip http://www.7-zip.org/ par exemple) et la copier dans le répertoire "exe" de votre projet.
Ensuite, cliquez sur le menu "Atelier/.NET/Utiliser un assemblage .NET dans votre projet".
Dans la fenêtre listant les assemblages disponibles, cliquez sur le bouton "Parcourir" et sélectionnez la dll RSA.dll que vous venez de copier.
Cliquez sur le bouton de validation pour l'importer dans votre projet.

Le code Windev est le suivant :

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
 
LOCAL
	sClePrivee est une chaîne
	sClePublique est une chaîne
	sMessErr est une chaîne
	iKeySize est un entier
	bOAEPPadding est un booléen
 
iKeySize = 2048
bOAEPPadding = Vrai
 
//Générer les clés privée et publique
RSATool.GenerateKeys(sClePrivee,sClePublique,sMessErr,iKeySize)
SI sMessErr <> "" ALORS
	Erreur(sMessErr)
	RENVOYER Faux
FIN
 
LOCAL
	sChaineAChiffrer est une chaîne
	sChaineChiffree est une chaîne
	sChaineDeChiffree est une chaîne
 
sChaineAChiffrer = "Message à chiffrer"
 
//Chiffrer le message (Attention, avec une clé de 2048 bits, la taille de la chaine à chiffrer ne peut pas excéder 214 caractères (octets pour être précis)
//et 86 caractères avec une clé de 1024 bits, en utilisant l'OAEP (Optimal Asymmetric Encryption Padding))
sChaineChiffree = RSATool.RSAEncrypt(sChaineAChiffrer,sClePublique,sMessErr,iKeySize,bOAEPPadding)
SI sMessErr <> "" ALORS
	Erreur(sMessErr)
	RENVOYER Faux
FIN
 
//Déchiffrer le message
sChaineDeChiffree = RSATool.RSADecrypt(sChaineChiffree,sClePrivee,sMessErr,iKeySize,bOAEPPadding)
SI sMessErr <> "" ALORS
	Erreur(sMessErr)
	RENVOYER Faux
FIN
 
Info(sChaineDeChiffree)
Plus d'infos et d'exemples ici :

https://fr.wikipedia.org/wiki/Chiffrement_RSA
https://gist.github.com/zachbonham/3...-crypto-cs-L50
http://www.csharpdeveloping.net/Snip..._algorithm_rsa

Concernant la taille maximale des données à chiffrer selon la taille de la clé de chiffrement :
http://info.townsendsecurity.com/bid...-with-rsa-keys

Bonne prog