Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        protected internal UnsignedDataInfo Encrypt <T>(T input)
        {
            UnsignedDataInfo info = new UnsignedDataInfo();

            if (input != null)
            {
                string finalJson  = JsonConvert.SerializeObject(input);
                byte[] encodeJson = Encoding.UTF8.GetBytes(finalJson);
                string json       = Convert.ToBase64String(encodeJson);
                byte[] jsonData   = Encoding.UTF8.GetBytes(json);
                info.data = EncryptionUtils.AesEncrypt(jsonData, provider.DecryptedKey);
                info.hMAC = EncryptionUtils.GenerateHMAC(json, provider.DecryptedKey);
            }
            return(info);
        }
Ejemplo n.º 3
0
        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 json       = Encoding.UTF8.GetString(jsonData);
                byte[] decodeJson = Convert.FromBase64String(json);
                string finalJson  = Encoding.UTF8.GetString(decodeJson);
                model    = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(finalJson);
                LastJson = finalJson;
            }
            return(model);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public GSTNResult <TokenResponseModel> RequestToken(string username, string otp)
        {
            TokenRequestModel model = new TokenRequestModel {
                action   = "AUTHTOKEN",
                username = username
            };

            model.app_key = EncryptionUtils.RsaEncrypt(GSTNConstants.GetAppKeyBytes());
            model.otp     = EncryptionUtils.AesEncrypt(otp, GSTNConstants.GetAppKeyBytes());
            var output = this.Post <TokenRequestModel, TokenResponseModel>(model);

            this.username     = username;
            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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 public static string AesEncrypt(string plainText, string key)
 {
     byte[] data     = UTF8Encoding.UTF8.GetBytes(plainText);
     byte[] keyBytes = Encoding.UTF8.GetBytes(key);
     return(EncryptionUtils.AesEncrypt(data, keyBytes));
 }