Skip to content

Commit 203c169

Browse files
abhishek.singhalabhishek.singhal
abhishek.singhal
authored and
abhishek.singhal
committed
GSTN API client initial upload.
1 parent c7a047a commit 203c169

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+6195
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
################################################################################
2+
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3+
################################################################################
4+
5+
/GSTN.API.Library/bin/Debug
6+
/GSTN.API.Console/bin/Debug
7+
/GSTN.API.Console/obj/Debug
8+
/.vs/GSTN.API/v14/.suo
9+
/GSTN.API.Library/obj/Debug
10+
/packages

GSTN.API.Console/App.config

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{112B5C4B-D577-40B8-8616-7D625F8DD577}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>GSTN.API.Console</RootNamespace>
11+
<AssemblyName>GSTN.API.Console</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Net.Http" />
44+
<Reference Include="System.Xml" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="Program.cs" />
48+
<Compile Include="Properties\AssemblyInfo.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="App.config" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<ProjectReference Include="..\GSTN.API.Library\GSTN.API.Library.csproj">
55+
<Project>{B3FC4B26-9C24-43FF-B55F-3B1AE5642050}</Project>
56+
<Name>GSTN.API.Library</Name>
57+
</ProjectReference>
58+
</ItemGroup>
59+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
60+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
61+
Other similar extension points exist, see Microsoft.Common.targets.
62+
<Target Name="BeforeBuild">
63+
</Target>
64+
<Target Name="AfterBuild">
65+
</Target>
66+
-->
67+
</Project>

GSTN.API.Console/Program.cs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using GSTN.API;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace GSTN.API.Console
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
string gstin = "05BDIPA7164F1ZT";
15+
string fp = "072016";
16+
System.Console.WriteLine("Press any key to start GSTR1");
17+
System.Console.ReadKey(false);
18+
TestGSTR1(gstin, fp);
19+
20+
System.Console.WriteLine("Press any key to start GSTR2");
21+
System.Console.ReadKey(false);
22+
TestGSTR2(gstin, fp);
23+
24+
System.Console.WriteLine("Press any key to start GSTR3");
25+
System.Console.ReadKey(false);
26+
TestGSTR3(gstin, fp);
27+
28+
System.Console.WriteLine("Press any key to end this program");
29+
System.Console.ReadKey(false);
30+
}
31+
private static void TestGSTR1(string gstin,string fp)
32+
{
33+
GSTNAuthClient client = new GSTNAuthClient();
34+
var result = client.RequestOTP(GSTNConstants.testUser);
35+
var result2 = client.RequestToken(GSTNConstants.testUser, GSTNConstants.otp);
36+
37+
GSTR1.GSTR1Total model = new GSTR1.GSTR1Total();
38+
GSTR1ApiClient client2 = new GSTR1ApiClient(client);
39+
model.b2b = client2.GetB2B(gstin, fp, "Y").Data;
40+
model.b2cl = client2.GetB2CL(gstin, fp, "01").Data;
41+
var result3 = client2.Save(model);
42+
43+
var model2 = client2.GetSummary(gstin, fp).Data;
44+
var result4 = client2.File(model2, "xx", "DSC", "kjdkjdkdkdkdkd");
45+
}
46+
private static void TestGSTR2(string gstin, string fp)
47+
{
48+
GSTNAuthClient client = new GSTNAuthClient();
49+
var result = client.RequestOTP(GSTNConstants.testUser);
50+
var result2 = client.RequestToken(GSTNConstants.testUser, GSTNConstants.otp);
51+
52+
GSTR2.GSTR2Total model = new GSTR2.GSTR2Total();
53+
GSTR2ApiClient client2 = new GSTR2ApiClient(client);
54+
model.b2b = client2.GetB2B(gstin, fp, "Y").Data;
55+
model.imp_g = client2.GetImpG(gstin, fp).Data;
56+
var result3 = client2.Save(model);
57+
58+
var model2 = client2.GetSummary(gstin, fp).Data;
59+
var result4 = client2.File(model2, "xx", "DSC", "kjdkjdkdkdkdkd");
60+
}
61+
private static void TestGSTR3(string gstin, string fp)
62+
{
63+
GSTNAuthClient client = new GSTNAuthClient();
64+
var result = client.RequestOTP(GSTNConstants.testUser);
65+
var result2 = client.RequestToken(GSTNConstants.testUser, GSTNConstants.otp);
66+
67+
GSTR3.GSTR3Total model = new GSTR3.GSTR3Total();
68+
GSTR3ApiClient client2 = new GSTR3ApiClient(client);
69+
var info = client2.Generate(gstin, fp).Data;
70+
model = client2.GetDetails(gstin, fp).Data;
71+
GSTR3.GSTR3SaveModel model2 = new GSTR3.GSTR3SaveModel();
72+
model2.rf_clm = model.rf_clm;
73+
var result3 = client2.Save(model2);
74+
var result4 = client2.File(model, "xx", "DSC", "kjdkjdkdkdkdkd");
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("GSTN.API.Console")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("GSTN.API.Console")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("112b5c4b-d577-40b8-8616-7d625f8dd577")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
using Microsoft.VisualBasic;
2+
using System;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Data;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
using System.Xml.Linq;
9+
using System.Threading.Tasks;
10+
11+
using System.IO;
12+
using System.Security.Cryptography;
13+
using System.Security.Cryptography.X509Certificates;
14+
using System.Text;
15+
namespace GSTN.API
16+
{
17+
18+
19+
public class EncryptionUtils
20+
{
21+
22+
public static X509Certificate2 getPublicKey()
23+
{
24+
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
25+
X509Certificate2 cert2 = new X509Certificate2("E:\\vs.com\\ERPv2\\FICO\\risersoft.app.exvat\\GSTN_PublicKey.cer");
26+
return cert2;
27+
}
28+
29+
public static string HMAC_Encrypt(string message, string secret)
30+
{
31+
secret = secret ?? "";
32+
var encoding = new System.Text.ASCIIEncoding();
33+
byte[] keyByte = encoding.GetBytes(secret);
34+
byte[] messageBytes = encoding.GetBytes(message);
35+
using (var HMACSHA256 = new HMACSHA256(keyByte))
36+
{
37+
byte[] hashmessage = HMACSHA256.ComputeHash(messageBytes);
38+
return Convert.ToBase64String(hashmessage);
39+
}
40+
41+
42+
}
43+
public static string GenerateHMAC(string message, byte[] EK)
44+
{
45+
using (var HMACSHA256 = new HMACSHA256(EK))
46+
{
47+
byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
48+
byte[] hashmessage = HMACSHA256.ComputeHash(data);
49+
return Convert.ToBase64String(hashmessage);
50+
}
51+
}
52+
public static string HMAC_Encrypt(byte[] EK)
53+
{
54+
using (var HMACSHA256 = new HMACSHA256())
55+
{
56+
byte[] hashmessage = HMACSHA256.ComputeHash(EK);
57+
return Convert.ToBase64String(hashmessage);
58+
}
59+
}
60+
61+
public static string Encrypt(string plainText, byte[] keyBytes)
62+
{
63+
byte[] dataToEncrypt = UTF8Encoding.UTF8.GetBytes(plainText);
64+
65+
AesManaged tdes = new AesManaged();
66+
67+
tdes.KeySize = 256;
68+
tdes.BlockSize = 128;
69+
tdes.Key = keyBytes;
70+
// Encoding.ASCII.GetBytes(key);
71+
tdes.Mode = CipherMode.ECB;
72+
tdes.Padding = PaddingMode.PKCS7;
73+
74+
ICryptoTransform crypt = tdes.CreateEncryptor();
75+
byte[] cipher = crypt.TransformFinalBlock(dataToEncrypt, 0, dataToEncrypt.Length);
76+
tdes.Clear();
77+
return Convert.ToBase64String(cipher, 0, cipher.Length);
78+
}
79+
80+
public static string Encrypt(string plainText, string key)
81+
{
82+
byte[] data = UTF8Encoding.UTF8.GetBytes(plainText);
83+
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
84+
return EncryptionUtils.Encrypt(data, keyBytes);
85+
86+
}
87+
88+
89+
public static string Encrypt(byte[] data, byte[] keys)
90+
{
91+
AesManaged tdes = new AesManaged();
92+
tdes.KeySize = 256;
93+
tdes.BlockSize = 128;
94+
tdes.Mode = CipherMode.ECB;
95+
tdes.Padding = PaddingMode.PKCS7;
96+
tdes.Key = keys;
97+
ICryptoTransform crypt = tdes.CreateEncryptor();
98+
byte[] cipher = crypt.TransformFinalBlock(data, 0, data.Length);
99+
return Convert.ToBase64String(cipher, 0, cipher.Length);
100+
}
101+
102+
public static byte[] Decrypt(string encryptedText, string key)
103+
{
104+
105+
byte[] dataToDecrypt = Convert.FromBase64String(encryptedText);
106+
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
107+
108+
return Decrypt(dataToDecrypt, keyBytes);
109+
110+
}
111+
112+
public static byte[] Decrypt(string encryptedText, byte[] keys)
113+
{
114+
byte[] dataToDecrypt = Convert.FromBase64String(encryptedText);
115+
return Decrypt(dataToDecrypt, keys);
116+
}
117+
118+
119+
120+
public static byte[] Decrypt(byte[] dataToDecrypt, byte[] keys)
121+
{
122+
123+
AesManaged tdes = new AesManaged();
124+
tdes.KeySize = 256;
125+
tdes.BlockSize = 128;
126+
tdes.Key = keys;
127+
tdes.Mode = CipherMode.ECB;
128+
tdes.Padding = PaddingMode.PKCS7;
129+
130+
ICryptoTransform decrypt__1 = tdes.CreateDecryptor();
131+
byte[] deCipher = decrypt__1.TransformFinalBlock(dataToDecrypt, 0, dataToDecrypt.Length);
132+
tdes.Clear();
133+
134+
return deCipher;
135+
}
136+
137+
138+
139+
140+
public static string EncryptTextWithPublicKey(string input)
141+
{
142+
byte[] bytesToBeEncrypted = Encoding.UTF8.GetBytes(input);
143+
return EncryptTextWithPublicKey(bytesToBeEncrypted);
144+
}
145+
146+
private static readonly byte[] Salt = new byte[] {
147+
10,
148+
20,
149+
30,
150+
40,
151+
50,
152+
60,
153+
70,
154+
80
155+
};
156+
public static byte[] CreateKey()
157+
{
158+
159+
System.Security.Cryptography.AesCryptoServiceProvider crypto = new System.Security.Cryptography.AesCryptoServiceProvider();
160+
crypto.KeySize = 256;
161+
crypto.GenerateKey();
162+
byte[] key = crypto.Key;
163+
return key;
164+
}
165+
166+
public static string EncryptTextWithPublicKey(byte[] bytesToBeEncrypted)
167+
{
168+
X509Certificate2 certificate = getPublicKey();
169+
RSACryptoServiceProvider RSA = (RSACryptoServiceProvider)certificate.PublicKey.Key;
170+
171+
byte[] bytesEncrypted = RSA.Encrypt(bytesToBeEncrypted, false);
172+
173+
string result = Convert.ToBase64String(bytesEncrypted);
174+
return result;
175+
}
176+
177+
178+
179+
}
180+
}
181+
182+

0 commit comments

Comments
 (0)