using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Core
{
///
/// Gestione licenze applicativi GLS (Legacy SteamWare)
///
public class licenseManGLS
{
#region Public Methods
///
/// restituisce data decodificata da authKey + applicazione + cliente...
///
/// The cliente.
/// The applicativo.
/// The licenze.
/// The authentication key.
///
public static DateTime expiryDateByAuthKey(string cliente, string applicativo, int licenze, string authKey)
{
DateTime answ = DateTime.Today.AddYears(-10);
string plainAuthKey = "";
try
{
string passPhrase = string.Format("{0}|{1}", cliente.PadLeft(50, ':'), applicativo);
plainAuthKey = SteamCrypto.DecryptString(authKey, passPhrase); // uso combinazione cliente+applicativo come passphrase!
answ = Convert.ToDateTime(plainAuthKey.Replace(string.Format("{0}#{1}-", cliente, applicativo.PadLeft(20, '-')), "").Replace(string.Format("%{0}%", licenze), ""));
}
catch
{ }
return answ;
}
///
/// Fornisce chiave MD5 x un cliente/applicativo/expiryDate
///
///
///
///
///
///
public static string getAuthKey(string cliente, string applicativo, int licenze, DateTime expiryDate)
{
string answ = "";
// algoritmo MD5 formato cliente#applicativo#expDate, via SQLdiventa
// SELECT CONVERT(VARCHAR(32), HashBytes('MD5', 'ETS#GPW#2013/12/31'), 2)
string plainAuthKey = string.Format("{0}#{1}-{2}%{3}%", cliente, applicativo.PadLeft(20, '-'), expiryDate.ToString("yyyy/MM/dd"), licenze);
string passPhrase = string.Format("{0}|{1}", cliente.PadLeft(50, ':'), applicativo);
answ = SteamCrypto.EncryptString(plainAuthKey, passPhrase); // uso combinazione cliente+applicativo come passphrase!
return answ;
}
///
/// Fornisce chiave MD5 x una chiave secondaria/di checksum data dai parametri in ingresso
/// MasterKey/string[] chiavi singole child/expiryDate
///
/// Chiave master da cui si parte
/// Payload che contiene le chiavi SUB (child) riferite alla master in formato JSon (compresso/no indent)
///
public static string getChecksumKey(string MasterKey, string Payload)
{
string answ = "";
answ = SteamCrypto.EncryptString(Payload, MasterKey);
return answ;
}
///
/// numero di licenze attive per cliente/applicativo
///
///
///
///
public static int getLicenseNum(string cliente, string applicativo)
{
// !!!FARE!!! chiamata a webservice 1/mese
int answ = 1;
// molto hard-coded e discutibile... licenze "perenni"
switch (cliente)
{
default:
answ = 1;
break;
}
return answ;
}
#endregion Public Methods
}
}