Skip to content

Commit

Permalink
Add files
Browse files Browse the repository at this point in the history
  • Loading branch information
pichid committed Jan 20, 2020
0 parents commit 6764612
Show file tree
Hide file tree
Showing 23 changed files with 756 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/

# Visual Studio Code
.vscode

# Rider
.idea

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ThaiNationalIDCard.NET

ThaiNationalIDCard.NET is wrapper classes for .NET based on the [PCSC](https://github.com/danm-de/pcsc-sharp) that provides access to the Thai National ID Card (Smart Card). The wrapper is written with .NET Standard version that are available on all .NET implementations.

# Example
* Console Application
* Web API

# Credits
* [ThaiNationalIDCard](https://github.com/chakphanu/ThaiNationalIDCard)
* [PC/SC wrapper classes for .NET](https://github.com/danm-de/pcsc-sharp)
34 changes: 34 additions & 0 deletions ThaiNationalIDCard.NET.Example.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using ThaiNationalIDCard.NET.Models;

namespace ThaiNationalIDCard.NET.Example.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
try
{
ThaiNationalIDCardReader cardReader = new ThaiNationalIDCardReader();
PersonalPhoto personalPhoto = cardReader.GetPersonalPhoto();

Console.WriteLine($"CitizenID: {personalPhoto.CitizenID}");
Console.WriteLine($"ThaiPersonalInfo: {personalPhoto.ThaiPersonalInfo}");
Console.WriteLine($"EnglishPersonalInfo: {personalPhoto.EnglishPersonalInfo}");
Console.WriteLine($"Sex: {personalPhoto.Sex}");
Console.WriteLine($"AddressInfo: {personalPhoto.AddressInfo}");
Console.WriteLine($"IssueDate: {personalPhoto.IssueDate}");
Console.WriteLine($"ExpireDate: {personalPhoto.ExpireDate}");
Console.WriteLine($"Issuer: {personalPhoto.Issuer}");
Console.WriteLine($"Photo: {personalPhoto.Photo}");
}
catch (Exception e)
{
Console.WriteLine(e);
}

Console.WriteLine("Please any key to exit...");
Console.ReadKey(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ThaiNationalIDCard.NET\ThaiNationalIDCard.NET.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using ThaiNationalIDCard.NET.Models;

namespace ThaiNationalIDCard.NET.Example.WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ReadersController : ControllerBase
{
private readonly ThaiNationalIDCardReader cardReader;

public ReadersController(ThaiNationalIDCardReader cardReader)
{
this.cardReader = cardReader;
}

[HttpGet("Read")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PersonalPhoto))]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult Read()
{
try
{
PersonalPhoto personalPhoto = cardReader.GetPersonalPhoto();

return Ok(personalPhoto);
}
catch (Exception e)
{
return BadRequest(e);
}
}
}
}
20 changes: 20 additions & 0 deletions ThaiNationalIDCard.NET.Example.WebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace ThaiNationalIDCard.NET.Example.WebApi
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55527",
"sslPort": 0
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/readers/read",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ThaiNationalIDCard.Example.WebApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5000"
}
}
}
42 changes: 42 additions & 0 deletions ThaiNationalIDCard.NET.Example.WebApi/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace ThaiNationalIDCard.NET.Example.WebApi
{
public class Startup
{
public IConfiguration Configuration { get; }

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();

services.AddScoped<ThaiNationalIDCardReader>();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Authors>Pichid Detson</Authors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ThaiNationalIDCard.NET\ThaiNationalIDCard.NET.csproj" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions ThaiNationalIDCard.NET.Example.WebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
37 changes: 37 additions & 0 deletions ThaiNationalIDCard.NET.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThaiNationalIDCard.NET", "ThaiNationalIDCard.NET\ThaiNationalIDCard.NET.csproj", "{754802D9-509B-4FE1-B9BB-8F0838B07AA7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThaiNationalIDCard.NET.Example.ConsoleApp", "ThaiNationalIDCard.NET.Example.ConsoleApp\ThaiNationalIDCard.NET.Example.ConsoleApp.csproj", "{94485686-CAF7-43FB-B425-DD9F13EFAFF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThaiNationalIDCard.NET.Example.WebApi", "ThaiNationalIDCard.NET.Example.WebApi\ThaiNationalIDCard.NET.Example.WebApi.csproj", "{EC52B1CF-6467-4506-A7BC-CAD49E9F202F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{754802D9-509B-4FE1-B9BB-8F0838B07AA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{754802D9-509B-4FE1-B9BB-8F0838B07AA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{754802D9-509B-4FE1-B9BB-8F0838B07AA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{754802D9-509B-4FE1-B9BB-8F0838B07AA7}.Release|Any CPU.Build.0 = Release|Any CPU
{94485686-CAF7-43FB-B425-DD9F13EFAFF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94485686-CAF7-43FB-B425-DD9F13EFAFF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94485686-CAF7-43FB-B425-DD9F13EFAFF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94485686-CAF7-43FB-B425-DD9F13EFAFF5}.Release|Any CPU.Build.0 = Release|Any CPU
{EC52B1CF-6467-4506-A7BC-CAD49E9F202F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC52B1CF-6467-4506-A7BC-CAD49E9F202F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC52B1CF-6467-4506-A7BC-CAD49E9F202F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC52B1CF-6467-4506-A7BC-CAD49E9F202F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61BA88EB-152B-47AA-970F-5E6FDF7BA682}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ThaiNationalIDCard.NET.Interfaces
{
public interface IThaiNationalIDCardAPDUCommand
{
byte[] GetResponse();
byte[] Select(byte[] command);
byte[] MinistryOfInteriorAppletCommand { get; }
byte[] CitizenIDCommand { get; }
byte[] PersonalInfoCommand { get; }
byte[] AddressInfoCommand { get; }
byte[] CardIssueExpireCommand { get; }
byte[] CardIssuerCommand { get; }
byte[][] PhotoCommand { get; }
}
}
51 changes: 51 additions & 0 deletions ThaiNationalIDCard.NET/Models/AddressInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace ThaiNationalIDCard.NET.Models
{
public class AddressInfo
{
public string HouseNo { get; set; }
public string VillageNo { get; set; }
public string Lane { get; set; }
public string Road { get; set; }
public string SubDistrict { get; set; }
public string District { get; set; }
public string Province { get; set; }

public AddressInfo(string addressInfo)
{
string[] infos = addressInfo.Split('#');

HouseNo = infos[0].Trim();
VillageNo = infos[1].Trim();
Lane = infos[2].Trim();
Road = infos[3].Trim();
SubDistrict = infos[5].Trim();
District = infos[6].Trim();
Province = infos[7].Trim();
}

public override string ToString()
{
string address = HouseNo;

if (!string.IsNullOrEmpty(VillageNo))
address += string.Format($" ม.{VillageNo}");

if (!string.IsNullOrEmpty(Lane))
address += string.Format($" ซ.{Lane}");

if (!string.IsNullOrEmpty(Road))
address += string.Format($" ถ.{Road}");

if (!string.IsNullOrEmpty(SubDistrict))
address += string.Format($" ต.{SubDistrict}");

if (!string.IsNullOrEmpty(District))
address += string.Format($" อ.{District}");

if (!string.IsNullOrEmpty(Province))
address += string.Format($" จ.{Province}");

return address;
}
}
}
16 changes: 16 additions & 0 deletions ThaiNationalIDCard.NET/Models/Personal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace ThaiNationalIDCard.NET.Models
{
public class Personal
{
public string CitizenID { get; set; }
public PersonalInfo ThaiPersonalInfo { get; set; }
public PersonalInfo EnglishPersonalInfo { get; set; }
public string Sex { get; set; }
public AddressInfo AddressInfo { get; set; }
public DateTime IssueDate { get; set; }
public DateTime ExpireDate { get; set; }
public string Issuer { get; set; }
}
}
Loading

0 comments on commit 6764612

Please sign in to comment.