示例#1
0
        public GSTNResult <OTPResponseModel> RequestOTP()
        {
            OTPRequestModel model = new OTPRequestModel {
                action   = "OTPREQUEST",
                username = userid,
                app_key  = EncryptionUtils.RsaEncrypt(GSTNConstants.GetAppKeyBytes())
            };
            var output = this.Post <OTPRequestModel, OTPResponseModel>(model);

            return(output);
        }
示例#2
0
        public GSTNResult <OTPResponseModel> RequestOTP()
        {
            dicParams.Clear();
            OTPRequestModel model = new OTPRequestModel {
                action   = "OTPREQUEST",
                username = this.username,
                app_key  = EncryptionUtils.RsaEncrypt(this.GetAppKeyBytes(), credential.cert_file_rsa)
            };
            string finalJson = this.Serialize(model);

            this.LogMessage(finalJson);
            dicParams.Add("RequestPayload", finalJson);
            var output = this.Post <OTPRequestModel, OTPResponseModel>(model);

            return(output);
        }
示例#3
0
        public virtual GSTNResult <TokenResponseModel> RequestToken(string otp)
        {
            PwdTokenRequestModel model = new PwdTokenRequestModel {
                action   = "ACCESSTOKEN",
                username = credential.username
            };

            model.app_key = EncryptionUtils.RsaEncrypt(this.GetAppKeyBytes(), credential.cert_file_rsa);
            byte[] dataToEncrypt = UTF8Encoding.UTF8.GetBytes(credential.password);
            model.password = EncryptionUtils.RsaEncrypt(dataToEncrypt, credential.cert_file_rsa);
            var output = this.Post <PwdTokenRequestModel, TokenResponseModel>(model);

            token             = output.Data;
            this.DecryptedKey = EncryptionUtils.AesDecrypt(token.sek, this.GetAppKeyBytes());

            return(output);
        }
        protected internal T Decrypt <T>(ResponseDataInfo output)
        {
            T model = default(T);

            if (output != null)
            {
                byte[] decryptREK = EncryptionUtils.AesDecrypt(output.rek, provider.DecryptedKey);
                byte[] jsonData   = EncryptionUtils.AesDecrypt(output.data, decryptREK);
                string testHmac   = EncryptionUtils.GenerateHMAC(jsonData, decryptREK);
                System.Console.WriteLine("HMAC Match:" + (output.hmac == testHmac));
                string base64Payload = UTF8Encoding.UTF8.GetString(jsonData);
                byte[] decodeJson    = Convert.FromBase64String(base64Payload);
                string finalJson     = Encoding.UTF8.GetString(decodeJson);
                model    = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(finalJson);
                LastJson = finalJson;
            }
            return(model);
        }
示例#5
0
        public GSTNResult <OTPResponseModel> Logout()
        {
            dicParams.Clear();
            RefreshTokenModel model = new RefreshTokenModel
            {
                action   = "LOGOUT",
                username = this.username
            };

            model.app_key    = EncryptionUtils.RsaEncrypt(this.GetAppKeyBytes(), credential.cert_file_rsa);
            model.auth_token = this.AuthToken();
            string finalJson = this.Serialize(model);

            dicParams.Add("RequestPayload", finalJson);
            var output = this.Post <RefreshTokenModel, OTPResponseModel>(model);

            return(output);
        }
示例#6
0
        public GSTNResult <TokenResponseModel> RefreshToken()
        {
            RefreshTokenModel model = new RefreshTokenModel
            {
                action   = "REFRESHTOKEN",
                username = userid
            };

            model.app_key    = EncryptionUtils.AesEncrypt(GSTNConstants.GetAppKeyBytes(), this.DecryptedKey);
            model.auth_token = this.AuthToken;
            var output = this.Post <RefreshTokenModel, TokenResponseModel>(model);

            token             = output.Data;
            this.AuthToken    = token.auth_token;
            this.DecryptedKey = EncryptionUtils.AesDecrypt(token.sek, GSTNConstants.GetAppKeyBytes());
            var Decipher = System.Text.Encoding.UTF8.GetString(DecryptedKey);

            return(output);
        }
        protected internal UnsignedDataInfo Encrypt <T>(T input)
        {
            UnsignedDataInfo info = new UnsignedDataInfo();

            if (input != null)
            {
                string finalJson = JsonConvert.SerializeObject(input, Newtonsoft.Json.Formatting.Indented,
                                                               new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                byte[] encodeJson    = UTF8Encoding.UTF8.GetBytes(finalJson);
                string base64Payload = Convert.ToBase64String(encodeJson);
                byte[] jsonData      = UTF8Encoding.UTF8.GetBytes(base64Payload);
                info.data = EncryptionUtils.AesEncrypt(jsonData, provider.DecryptedKey);
                info.hmac = EncryptionUtils.GenerateHMAC(jsonData, provider.DecryptedKey);
            }
            return(info);
        }
示例#8
0
        public GSTNResult <TokenResponseModel> RequestToken(string otp)
        {
            TokenRequestModel model = new TokenRequestModel {
                action   = "AUTHTOKEN",
                username = userid
            };

            model.app_key = EncryptionUtils.RsaEncrypt(GSTNConstants.GetAppKeyBytes());
            byte[] dataToEncrypt = UTF8Encoding.UTF8.GetBytes(otp);
            model.otp = EncryptionUtils.AesEncrypt(dataToEncrypt, GSTNConstants.GetAppKeyBytes());
            var output = this.Post <TokenRequestModel, TokenResponseModel>(model);

            this.userid       = userid;
            token             = output.Data;
            this.AuthToken    = token.auth_token;
            this.DecryptedKey = EncryptionUtils.AesDecrypt(token.sek, GSTNConstants.GetAppKeyBytes());
            var Decipher = System.Text.Encoding.UTF8.GetString(DecryptedKey);

            return(output);
        }
示例#9
0
        public GSTNResult <TokenResponseModel> RequestToken(string otp)
        {
            dicParams.Clear();
            PwdTokenRequestModel model = new PwdTokenRequestModel()
            {
                app_key  = EncryptionUtils.RsaEncrypt(this.GetAppKeyBytes(), credential.cert_file_rsa),
                action   = "ACCESSTOKEN",
                username = this.username,
                password = EncryptionUtils.RsaEncrypt(UTF8Encoding.UTF8.GetBytes(this.password), credential.cert_file_rsa)
            };
            string finalJson = this.Serialize(model);

            this.LogMessage(finalJson);
            dicParams.Add("RequestPayload", finalJson);
            var output = this.Post <PwdTokenRequestModel, TokenResponseModel>(model);

            try
            {
                if (output.Data != null)
                {
                    output.Data.auth_token = output.Data.authtoken;
                    this.token             = output.Data;
                    this.DecryptedKey      = EncryptionUtils.AesDecrypt(token.sek, this.GetAppKeyBytes());
                    this.LogMessage(this.token.auth_token);

                    if (myUtils.cValTN(output.Data.expiry) == 0 && output.Data.auth_token_expires_at.HasValue)
                    {
                        output.Data.expiry = (int)((output.Data.auth_token_expires_at.Value - DateTime.Now).TotalMinutes);
                    }
                    if (output.Data.expiry <= 0)
                    {
                        output.Data.expiry = 360;
                    }
                }
            }
            catch (Exception ex)
            {
                output = this.BuildExceptionResult <TokenResponseModel>(ex);
            }
            return(output);
        }
示例#10
0
        public GSTNResult <TokenResponseModel> RefreshToken()
        {
            dicParams.Clear();
            RefreshTokenModel model = new RefreshTokenModel
            {
                action   = "REFRESHTOKEN",
                username = this.username
            };

            model.app_key    = EncryptionUtils.AesEncrypt(this.GetAppKeyBytes(), this.DecryptedKey);
            model.auth_token = this.AuthToken();
            string finalJson = this.Serialize(model);

            dicParams.Add("RequestPayload", finalJson);
            var output = this.Post <RefreshTokenModel, TokenResponseModel>(model);

            this.token        = output.Data;
            this.DecryptedKey = EncryptionUtils.AesDecrypt(token.sek, this.GetAppKeyBytes());
            var Decipher = System.Text.Encoding.UTF8.GetString(DecryptedKey);

            return(output);
        }