Anf, è stata dura ma sembra che qualcosa sia riuscito a trovarlo, era in VB.Net ma l'ho riconvertito in C#.
Per prima cosa includere nel progetto il riferimetno a System.Web, poi:
codice:
using System;
using System.Xml;
using System.Security.Cryptography;
using System.Web.Security;
using System.Text;
class Crypto
{
string myKey = "";
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
static void Main(string[] args)
{
Crypto cry = new Crypto();
string str = "Prova";
str = cry.Cifra(str);
str = cry.DeCifra(str);
}
public Crypto()
{
//Inserire codice di configurazione della classe
myKey = "StringaPersonalizzata";
}
public string DeCifra(string testo)
{
des.Key = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(myKey));
des.Mode = CipherMode.ECB;
ICryptoTransform desdencrypt = des.CreateDecryptor();
byte[] buff = Convert.FromBase64String(testo);
return ASCIIEncoding.ASCII.GetString(desdencrypt.TransformFinalBlock(buff, 0, buff.Length));
}
public string Cifra(string testo)
{
des.Key = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(myKey));
des.Mode = CipherMode.ECB;
ICryptoTransform desdencrypt = des.CreateEncryptor();
ASCIIEncoding MyASCIIEncoding = new ASCIIEncoding();
byte[] buff = ASCIIEncoding.ASCII.GetBytes(testo);
return Convert.ToBase64String(desdencrypt.TransformFinalBlock(buff, 0, buff.Length));
}
}
La stringa Prova viene convertita in TNzIINuPcaY= e poi viene riconvertiti in Prova.
Ovviamente il risultato cambia in base alla stringa personalizzata.
Spero vi possa essere utile, anche se non è RSA