-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pichid
committed
Jan 20, 2020
0 parents
commit 6764612
Showing
23 changed files
with
756 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
ThaiNationalIDCard.NET.Example.ConsoleApp/ThaiNationalIDCard.NET.Example.ConsoleApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
ThaiNationalIDCard.NET.Example.WebApi/Controllers/ReadersController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
}); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
ThaiNationalIDCard.NET.Example.WebApi/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
ThaiNationalIDCard.NET.Example.WebApi/ThaiNationalIDCard.NET.Example.WebApi.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
9 changes: 9 additions & 0 deletions
9
ThaiNationalIDCard.NET.Example.WebApi/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
ThaiNationalIDCard.NET/Interfaces/IThaiNationalIDCardAPDUCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
Oops, something went wrong.