public static string DECODE_DATA(string data)
        {
            try
            {
                string final_output = string.Empty;

                if (string.IsNullOrEmpty(data))
                {
                    throw new HttpResponseException(HttpStatusCode.NoContent);
                }
                string[] values = data.Split('.');

                string RSA_ENCRYPTED_AES_KEY = values[0].Replace(" ", "+");
                string ENCRYPTED_DATA        = values[1].Replace(" ", "+");

                string AES_KEY_PAIR = RSA_MODULE.RSA_Decrypt(RSA_ENCRYPTED_AES_KEY, RSA_MODULE.server_side_private_key_generator());

                if (string.IsNullOrEmpty(AES_KEY_PAIR))
                {
                    throw new HttpResponseException(HttpStatusCode.NoContent);
                }

                CLIEINT_AES_KEYS obj_AES = JsonConvert.DeserializeObject <CLIEINT_AES_KEYS>(AES_KEY_PAIR);

                final_output = AES_MODULE.AES_DECRYPTION_DATA(ENCRYPTED_DATA, obj_AES.KEY, obj_AES.IV);
                if (string.IsNullOrEmpty(final_output))
                {
                    throw new HttpResponseException(HttpStatusCode.NoContent);
                }

                return(final_output);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Пример #2
0
        public static string DECODE_DATA(string data)
        {
            string token_json_format = string.Empty;
            string final_output      = string.Empty;

            //spliting string into string array
            if (string.IsNullOrEmpty(data))
            {
                throw new HttpResponseException(HttpStatusCode.NoContent);
            }
            string[] values = data.Split('.');

            //assigning parameters
            string TOKEN = values[0].Replace(" ", "+");
            string RSA_ENCRYPTED_AES_KEY = values[1].Replace(" ", "+");
            string ENCRYPTED_DATA        = values[2].Replace(" ", "+");

            try
            {
                //decrypting token to get token json string
                token_json_format = AES_MODULE.AES_DECRYPTION_DATA(TOKEN, CORE_MODULE.TOKEN_AES_KEY, CORE_MODULE.TOKEN_AES_IV);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }
            //converting json string into model object
            TOKEN_MODEL token_params = JsonConvert.DeserializeObject <TOKEN_MODEL>(token_json_format);

            //checking expiry time
            if (!expiry_time_check(token_params.EXPIRY_TIME))
            {
                throw new HttpResponseException(HttpStatusCode.RequestTimeout);
            }
            //checking roles
            if (!roles_check(token_params.ROLES, CORE_MODULE.roles))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }
            //checking issuer
            if (!issuer_check(token_params.ISSUER))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }
            //checking audience
            if (!audience_check(token_params.AUDIENCE))
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            try
            {
                //decrypting aes key pair for data decryption
                string AES_KEY_PAIR = RSA_MODULE.RSA_Decrypt(RSA_ENCRYPTED_AES_KEY, RSA_MODULE.server_side_private_key_generator());

                if (string.IsNullOrEmpty(AES_KEY_PAIR))
                {
                    throw new HttpResponseException(HttpStatusCode.NoContent);
                }

                //creating model object for key pair
                CLIEINT_AES_KEYS obj_AES = JsonConvert.DeserializeObject <CLIEINT_AES_KEYS>(AES_KEY_PAIR);

                //decryption of data using AES key pair
                final_output = AES_MODULE.AES_DECRYPTION_DATA(ENCRYPTED_DATA, obj_AES.KEY, obj_AES.IV);
                if (string.IsNullOrEmpty(final_output))
                {
                    throw new HttpResponseException(HttpStatusCode.NoContent);
                }

                CORE_MODULE.roles.Clear();

                //returning decrypted value
                return(final_output);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }