using System.Security.Cryptography;
protected static string SecretKey = "nei5XieQuoGhah1u";
protected static string SecretFixed = "@portale_unicoop_tirreno";
public static void Main()
protected static void Encrypt(string clearText) {
string B64Part0Key = "OWRmMGI1MDdlMTdmZDQ5Nw==";
byte[] b = Convert.FromBase64String(B64Part0Key);
string Part0Key = System.Text.Encoding.UTF8.GetString(b);
string Part1Key = CalculateMD5Hash(Program.SecretKey + Program.SecretFixed);
Part1Key = Part1Key.Substring(0, 16);
Console.WriteLine(Part0Key);
Console.WriteLine(Part1Key);
string KeyStr = Part0Key + Part1Key;
Console.WriteLine(KeyStr);
byte[] key = System.Text.Encoding.UTF8.GetBytes(KeyStr);
byte[] encryptedBytes = null;
byte[] bytesToBeEncrypted = System.Text.Encoding.UTF8.GetBytes(clearText);
using (MemoryStream ms = new MemoryStream())
using (RijndaelManaged AES = new RijndaelManaged())
AES.Mode = CipherMode.CBC;
AES.Padding = PaddingMode.PKCS7;
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
encryptedBytes = ms.ToArray();
Console.WriteLine(AES.IV.Length);
string retStr = Convert.ToBase64String(encryptedBytes);
string ivStr = Convert.ToBase64String(AES.IV);
Console.WriteLine(retStr);
Console.WriteLine("https://local.portale-unicoop.netseven.it/n7-sso-api/test-decrypt2/fromnet7/"+Part0Key+","+retStr+","+ivStr);
protected static string CalculateMD5Hash(string input)
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
sb.Append(hash[i].ToString("x2"));