Example #1
0
        /// <summary>
        /// Separa i dati della stringa Decifrata, restituendo un Udt con i valori corretti.
        /// </summary>
        /// <param name="value">La stringa DECIFRATA.</param>
        /// <param name="Udt">La classe con Utente/Data</param>
        static void GetDateUser(string value, ref dtoUrlUserDateToken Udt, UrlUserTokenFormat format)
        {
            switch (format)
            {
            case UrlUserTokenFormat.PrefixDateTimeLogin:
                GetDateUserPrefixDateTimeLogin(value, ref Udt);
                break;

            case UrlUserTokenFormat.DateTimeLogin:
                GetDateUserDateTimeLogin(value, ref Udt);
                break;

            case UrlUserTokenFormat.LoginDateTime:
                GetDateUserLoginDateTime(value, ref Udt);
                break;

            default:
                GetDateUserDateTimeLogin(value, ref Udt);
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Effettua la decifratura della stringa.
        /// </summary>
        /// <param name="value">La stringa a base 64 da decifrare. VEDI REMARKS</param>
        /// <param name="alg">L'algoritmo utilizzato (Testato solo il Rijndael)</param>
        /// <param name="key">La chiave di cifratura, come stringa a base 64.</param>
        /// <param name="iv">Il vettore di cifratura, come stringa a base 64.</param>
        /// <returns>Una classe con UserName e Datetime corrispondente.</returns>
        /// <remarks>
        /// 1. value: gli spazi vengono convertiti in '+', a causa del passaggio via querystring che fa la conversione inversa. Html non fa una mazza.
        /// 2. numero iniziale: eventualmente il numero iniziale può essere utilizzato come ID dell'accesso, per non essere poi più utilizzato, purchè univoco. Al momento è inutilizzato.</remarks>
        ///

        public static dtoUrlUserDateToken Decrypt(string token, EncryptionInfo encryptionInfo, UrlUserTokenFormat tokenFormat)
        {
            dtoUrlUserDateToken UdT = new dtoUrlUserDateToken();

            byte[] DecipherText;
            byte[] cypher;
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            string DecriptString          = "";

            cypher = Convert.FromBase64String(token.Replace(" ", "+"));
            try
            {
                Decryptor dec = new Decryptor(encryptionInfo.EncryptionAlgorithm);
                DecipherText  = dec.Decrypt(cypher, Convert.FromBase64String(encryptionInfo.Key), Convert.FromBase64String(encryptionInfo.InitializationVector));
                DecriptString = enc.GetString(DecipherText);
            }
            catch (Exception ex)
            {
                UdT.ExceptionString = "Message=" + ex.Message + "\n\r";
                if (ex.InnerException != null)
                {
                    UdT.ExceptionString += "InnerException=" + ex.InnerException.ToString();
                }
            }
            if (DecriptString != "")
            {
                GetDateUser(DecriptString, ref UdT, tokenFormat);
            }
            return(UdT);
        }