using System; namespace SteamWare { /// /// gestione licenze applicativi /// public class licenseMan { /// /// 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) { case "SteamWare": answ = 50; break; case "ETS": if (applicativo == "GPW") { answ = 35; } break; case "SPS": if (applicativo == "GPW") { answ = 11; } break; default: answ = 1; break; } 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; } /// /// 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 (Exception exc) { logger.lg.scriviLog(string.Format("Errore decodifica auth key:{0}AuthKey: {1}{0}cliente:{2}{0}applicativo:{3}{0}errore:{4}", Environment.NewLine, authKey, cliente, applicativo, exc), tipoLog.EXCEPTION); } return answ; } } }