Si infatti erano sbagliate le lunghezze.
Cercavo un metodo con chiave che andasse bene sia per UWP che per altri sistemi in modo tale che la criptazione risultasse la stessa.
E quindi ho optato per questa soluzione che mi permette di impostare una chiave con la stessa lunghezza:
UWP
class CriptoSystem
{
private static string AES_Key = "xxxxxxxxxxxxxxxxxxxxxxxx";
private static string AES_IV = "yyyyyyyy";
public static string TDES_encrypt(string Input)
{
try
{
using (var tdes = System.Security.Cryptography.TripleDES.Create())
{
tdes.Key = UTF8Encoding.UTF8.GetBytes(AES_Key);
tdes.IV = UTF8Encoding.UTF8.GetBytes(AES_IV);
tdes.Mode = System.Security.Cryptography.CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(Input);
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
}
catch (Exception ex)
{
throw new Exception("Errore durante la criptazione della chiave (TripleDES)");
}
}
public static string TDES_decrypt(string Input)
{
try
{
using (var tdes = System.Security.Cryptography.TripleDES.Create())
{
tdes.Key = UTF8Encoding.UTF8.GetBytes(AES_Key);
tdes.IV = UTF8Encoding.UTF8.GetBytes(AES_IV);
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] toDencryptArray = Convert.FromBase64String(Input);
byte[] resultArray = cTransform.TransformFinalBlock(toDencryptArray, 0, toDencryptArray.Length);
return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
}
}
catch (Exception ex)
{
throw new Exception("Errore durante la decriptazione della chiave (TripleDES)");
}
}
}
ALTRO
class CriptoSystem
{
private static string AES_Key = "xxxxxxxxxxxxxxxxxxxxxxxx";
private static string AES_IV = "yyyyyyyy";
public static string TDES_encrypt(string Input)
{
try
{
using (TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider())
{
tdes.Key = UTF8Encoding.UTF8.GetBytes(AES_Key);
tdes.IV = UTF8Encoding.UTF8.GetBytes(AES_IV);
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(Input);
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
tdes.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
}
catch (Exception ex)
{
throw new Exception("Errore durante la criptazione della chiave (TripleDES)");
}
}
public static string TDES_decrypt(string Input)
{
try
{
using (TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider())
{
tdes.Key = UTF8Encoding.UTF8.GetBytes(AES_Key);
tdes.IV = UTF8Encoding.UTF8.GetBytes(AES_IV);
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] toDencryptArray = Convert.FromBase64String(Input);
byte[] resultArray = cTransform.TransformFinalBlock(toDencryptArray, 0, toDencryptArray.Length);
tdes.Clear();
return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
}
}
catch (Exception ex)
{
throw new Exception("Errore durante la decriptazione della chiave (TripleDES)");
}
}
}