Commit e454f69fd55c15644a06ec5659045f3eff4f63aa
1 parent
118c9911
feat(all):etradeclient第一次提交客户端相关代码全部在这个工程下面,第一提交 。
Showing
37 changed files
with
3605 additions
and
0 deletions
Too many changes to show.
To preserve performance only 37 of 540 files are displayed.
card_file_tool/DLCardTool.sln
0 → 100644
1 | + | |
2 | +Microsoft Visual Studio Solution File, Format Version 12.00 | |
3 | +# Visual Studio 2013 | |
4 | +VisualStudioVersion = 12.0.31101.0 | |
5 | +MinimumVisualStudioVersion = 10.0.40219.1 | |
6 | +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DLCardTool", "DLCardTool\DLCardTool.vcxproj", "{EE7AE382-8502-4D97-A6AE-3E9504311E7F}" | |
7 | +EndProject | |
8 | +Global | |
9 | + GlobalSection(SolutionConfigurationPlatforms) = preSolution | |
10 | + Debug|Win32 = Debug|Win32 | |
11 | + Release|Win32 = Release|Win32 | |
12 | + EndGlobalSection | |
13 | + GlobalSection(ProjectConfigurationPlatforms) = postSolution | |
14 | + {EE7AE382-8502-4D97-A6AE-3E9504311E7F}.Debug|Win32.ActiveCfg = Debug|Win32 | |
15 | + {EE7AE382-8502-4D97-A6AE-3E9504311E7F}.Debug|Win32.Build.0 = Debug|Win32 | |
16 | + {EE7AE382-8502-4D97-A6AE-3E9504311E7F}.Release|Win32.ActiveCfg = Release|Win32 | |
17 | + {EE7AE382-8502-4D97-A6AE-3E9504311E7F}.Release|Win32.Build.0 = Release|Win32 | |
18 | + EndGlobalSection | |
19 | + GlobalSection(SolutionProperties) = preSolution | |
20 | + HideSolutionNode = FALSE | |
21 | + EndGlobalSection | |
22 | +EndGlobal | ... | ... |
card_file_tool/DLCardTool/DLCardManager.h
0 → 100644
1 | +// 作者:刘野 | |
2 | +// 卡片硬件操作库导出接口。 | |
3 | +// 包含dll导出接口和so库导出接口 | |
4 | + | |
5 | +#ifndef DL_CARD_MANAGER_H | |
6 | +#define DL_CARD_MANAGER_H | |
7 | + | |
8 | +#define DL_DLL_API extern "C" __declspec(dllexport) | |
9 | + | |
10 | + | |
11 | +/* 连接读卡器 */ | |
12 | +DL_DLL_API int __stdcall DLCConnectDevice(); | |
13 | + | |
14 | +/* 关闭读卡器 */ | |
15 | +DL_DLL_API int __stdcall DLCDisconnectDevice(); | |
16 | + | |
17 | +/* 寻卡 */ | |
18 | +DL_DLL_API int __stdcall DLCFindCard(); | |
19 | + | |
20 | +/* | |
21 | + * 验证秘钥 | |
22 | + * 输入16字节秘钥key_。 | |
23 | + * 返回值返回结果 | |
24 | + * */ | |
25 | +DL_DLL_API int __stdcall DLCAuthenticationKey(const unsigned char* dir, const unsigned char key_id, const unsigned char* key); | |
26 | + | |
27 | +/* | |
28 | + * 读取数据 | |
29 | + * 输入dir2字节目录标识、file_id1字节文件标识、read_offset2字节、 | |
30 | + * data_len2字节、read_key16字节读秘钥(没有置空)和read_data(长度依据读取长度而定)。 | |
31 | + * 输出结果填入read_data。 | |
32 | + * */ | |
33 | +DL_DLL_API int __stdcall DLCReadCardData(const unsigned char* dir, const unsigned char file_id, const unsigned int data_offset, const unsigned int data_len, const unsigned char* read_key, unsigned char* read_data); | |
34 | + | |
35 | +/* | |
36 | +* 写入数据 | |
37 | +* 输入dir2字节目录标识、file_id2字节文件标识、read_offset2字节、 | |
38 | +* data_len2字节、read_key16字节读秘钥(没有置空)和read_data(长度依据读取长度而定)。 | |
39 | +* 输出结果填入read_data。 | |
40 | +* */ | |
41 | +DL_DLL_API int __stdcall DLCWriteCardData(const unsigned char* dir, const unsigned char file_id, const unsigned int data_offset, const unsigned int data_len, const unsigned char* write_key, const unsigned char* write_data); | |
42 | + | |
43 | +/* | |
44 | + * 安装/更新秘钥 | |
45 | + * 输入dir2字节目录标识、key_id1字节文件标识、key_type32位秘钥类型、 | |
46 | + * main_key16字节主控秘钥(没有置空)、new_key16字节新秘钥。 | |
47 | + **/ | |
48 | +DL_DLL_API int __stdcall DLCInstallKey(const unsigned char* dir, const unsigned char key_id, const int key_type, const unsigned char* main_key, const unsigned char* new_key); | |
49 | + | |
50 | +/* | |
51 | + * 建立文件 | |
52 | + * 输入parent_dir2字节父目录、parent_key2字节父目录主控秘钥、file_name2字节文件标识、 | |
53 | + * file_size2字节文件大小、safe_type4字节安全类型和file_type4字节文件类型 | |
54 | + **/ | |
55 | +DL_DLL_API int __stdcall DLCCreateFile(const unsigned char* parent_dir, const unsigned char* parent_key, const unsigned char* file_name, const unsigned char* file_size, const int file_type); | |
56 | + | |
57 | + | |
58 | +DL_DLL_API int __stdcall DLCSelectFile(const unsigned char* dir); | |
59 | + | |
60 | +//SO库API | |
61 | +// | |
62 | +/* | |
63 | + * 该函数用以获取8字节随机数 | |
64 | + * 输入5字节的无符号字符型数组指针,函数将更改数组内容,输出5字节指令。 | |
65 | + * 返回值返回错误码。 | |
66 | + */ | |
67 | +int __stdcall DLCSOGetRandom(unsigned char* get_randam_cmd); | |
68 | + | |
69 | +/* | |
70 | + * 该函数用于验证秘钥。 | |
71 | + * 输入key_id1字节秘钥标识、key16字节16进制秘钥值和random8字节16进制随机数,返回cmd13字节16进制指令。 | |
72 | + * 返回值返回结果。 | |
73 | + */ | |
74 | +int __stdcall DLCSOAuthenticationKey(const unsigned char key_id, const unsigned char* key, const unsigned char* random, unsigned char* cmd); | |
75 | + | |
76 | +/* | |
77 | + * 该函数用于读取数据。 | |
78 | + * 输入data_offfset数据初始偏移,data_offfset最大为ffff,data_len数据长度,data_len最大为ff,返回16进制cmd指令,cmd数组长度 = data_len + 5。 | |
79 | + * 读出的数据将存在data_中。 | |
80 | + * 返回值返回错误码。 | |
81 | + */ | |
82 | +int __stdcall DLCSOReadData(const unsigned int data_offfset, const unsigned int data_len, unsigned char* cmd); | |
83 | + | |
84 | +/* | |
85 | +* 该函数用于写入数据。 | |
86 | +* 输入write_key字节16进制读秘钥(没有置空)、random8字节16进制随机数(没有置空)、data_offfset2字节数据初始偏移、data_len2字节数据长度和data16进制数据,cmd数组长度 = data_len + 9。 | |
87 | +* 返回值返回错误码。 | |
88 | +*/ | |
89 | +int __stdcall DLCSOWriteData(const unsigned char* write_key, const unsigned char* random, const unsigned int data_offfset, const unsigned int data_len, const unsigned char* data, unsigned char* cmd); | |
90 | + | |
91 | + | |
92 | +/*该函数用于选择目录 | |
93 | + *输入dir两字节16进制目录标识,返回cmd7字节16进制指令 | |
94 | + **/ | |
95 | +int __stdcall DLCSOSelectDir(const unsigned char* dir, unsigned char* cmd); | |
96 | + | |
97 | +#endif //end DL_CARD_MANAGER_H | |
0 | 98 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLCardTool.cpp
0 → 100644
1 | + | |
2 | +// DLCardTool.cpp : 定义应用程序的类行为。 | |
3 | +// | |
4 | + | |
5 | +#include "stdafx.h" | |
6 | +#include "DLCardTool.h" | |
7 | +#include "DLCardToolDlg.h" | |
8 | + | |
9 | +#ifdef _DEBUG | |
10 | +#define new DEBUG_NEW | |
11 | +#endif | |
12 | + | |
13 | +static const wchar_t* APP_ID = L"DILIGROUP.DLCardTool.V1.0"; | |
14 | +// CDLCardToolApp | |
15 | + | |
16 | +BEGIN_MESSAGE_MAP(CDLCardToolApp, CWinApp) | |
17 | + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) | |
18 | +END_MESSAGE_MAP() | |
19 | + | |
20 | + | |
21 | +// CDLCardToolApp 构造 | |
22 | + | |
23 | +CDLCardToolApp::CDLCardToolApp() | |
24 | +{ | |
25 | + // 支持重新启动管理器 | |
26 | + m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; | |
27 | + | |
28 | + SetAppID(APP_ID); | |
29 | +} | |
30 | + | |
31 | + | |
32 | +// 唯一的一个 CDLCardToolApp 对象 | |
33 | + | |
34 | +CDLCardToolApp theApp; | |
35 | + | |
36 | +// CDLCardToolApp 初始化 | |
37 | + | |
38 | +BOOL CDLCardToolApp::InitInstance() | |
39 | +{ | |
40 | +//TODO: call AfxInitRichEdit2() to initialize richedit2 library. | |
41 | + AfxInitRichEdit2(); | |
42 | + // 如果一个运行在 Windows XP 上的应用程序清单指定要 | |
43 | + // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, | |
44 | + //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 | |
45 | + INITCOMMONCONTROLSEX InitCtrls; | |
46 | + InitCtrls.dwSize = sizeof(InitCtrls); | |
47 | + // 将它设置为包括所有要在应用程序中使用的 | |
48 | + // 公共控件类。 | |
49 | + InitCtrls.dwICC = ICC_WIN95_CLASSES; | |
50 | + InitCommonControlsEx(&InitCtrls); | |
51 | + | |
52 | + CWinApp::InitInstance(); | |
53 | + | |
54 | + | |
55 | + AfxEnableControlContainer(); | |
56 | + | |
57 | + // 创建 shell 管理器,以防对话框包含 | |
58 | + // 任何 shell 树视图控件或 shell 列表视图控件。 | |
59 | + CShellManager *pShellManager = new CShellManager; | |
60 | + | |
61 | + // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 | |
62 | + CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); | |
63 | + | |
64 | + if (!m_instance_mgr.Register(APP_ID)) | |
65 | + { | |
66 | + return false; | |
67 | + } | |
68 | + | |
69 | + SetRegistryKey(APP_ID); | |
70 | + | |
71 | + CDLCardToolDlg dlg; | |
72 | + m_pMainWnd = &dlg; | |
73 | + INT_PTR nResponse = dlg.DoModal(); | |
74 | + if (nResponse == IDOK) | |
75 | + { | |
76 | + // TODO: 在此放置处理何时用 | |
77 | + // “确定”来关闭对话框的代码 | |
78 | + } | |
79 | + else if (nResponse == IDCANCEL) | |
80 | + { | |
81 | + // TODO: 在此放置处理何时用 | |
82 | + // “取消”来关闭对话框的代码 | |
83 | + } | |
84 | + else if (nResponse == -1) | |
85 | + { | |
86 | + TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); | |
87 | + TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); | |
88 | + } | |
89 | + | |
90 | + // 删除上面创建的 shell 管理器。 | |
91 | + if (pShellManager != NULL) | |
92 | + { | |
93 | + delete pShellManager; | |
94 | + } | |
95 | + | |
96 | + // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, | |
97 | + // 而不是启动应用程序的消息泵。 | |
98 | + return FALSE; | |
99 | +} | |
100 | + | |
101 | +// InstanceManager | |
102 | +CDLCardToolApp::InstanceManager::InstanceManager() : m_mutex_handle(nullptr) | |
103 | +{} | |
104 | + | |
105 | +CDLCardToolApp::InstanceManager::~InstanceManager() | |
106 | +{ | |
107 | + Unregister(); | |
108 | +} | |
109 | + | |
110 | +bool CDLCardToolApp::InstanceManager::Register(const std::wstring& app_id) | |
111 | +{ | |
112 | + HANDLE hHandle = CreateMutex(NULL, TRUE, app_id.c_str()); | |
113 | + if (ERROR_ALREADY_EXISTS == GetLastError()) | |
114 | + { | |
115 | + // Log | |
116 | + return false; | |
117 | + } | |
118 | + m_mutex_handle = hHandle; | |
119 | + return true; | |
120 | +} | |
121 | + | |
122 | +void CDLCardToolApp::InstanceManager::Unregister() | |
123 | +{ | |
124 | + if (nullptr != m_mutex_handle) | |
125 | + { | |
126 | + ReleaseMutex(m_mutex_handle); // Explicitly release mutex | |
127 | + CloseHandle(m_mutex_handle); // close handle before terminating | |
128 | + m_mutex_handle = nullptr; | |
129 | + } | |
130 | +} | |
131 | + | ... | ... |
card_file_tool/DLCardTool/DLCardTool.h
0 → 100644
1 | + | |
2 | +// DLCardTool.h : PROJECT_NAME 应用程序的主头文件 | |
3 | +// | |
4 | + | |
5 | +#pragma once | |
6 | + | |
7 | +#ifndef __AFXWIN_H__ | |
8 | + #error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件" | |
9 | +#endif | |
10 | + | |
11 | +#include "resource.h" // 主符号 | |
12 | + | |
13 | + | |
14 | +// CDLCardToolApp: | |
15 | +// 有关此类的实现,请参阅 DLCardTool.cpp | |
16 | +// | |
17 | + | |
18 | +class CDLCardToolApp : public CWinApp | |
19 | +{ | |
20 | +public: | |
21 | + CDLCardToolApp(); | |
22 | + | |
23 | + class InstanceManager | |
24 | + { | |
25 | + public: | |
26 | + InstanceManager(); | |
27 | + ~InstanceManager(); | |
28 | + bool Register(const std::wstring& app_id); | |
29 | + void Unregister(); | |
30 | + private: | |
31 | + HANDLE m_mutex_handle; | |
32 | + }; | |
33 | + | |
34 | +// 重写 | |
35 | +public: | |
36 | + virtual BOOL InitInstance(); | |
37 | + | |
38 | +// 实现 | |
39 | + | |
40 | + DECLARE_MESSAGE_MAP() | |
41 | + | |
42 | +private: | |
43 | + InstanceManager m_instance_mgr; | |
44 | + | |
45 | +}; | |
46 | + | |
47 | +extern CDLCardToolApp theApp; | |
0 | 48 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLCardTool.rc
0 → 100644
card_file_tool/DLCardTool/DLCardTool.vcxproj
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
3 | + <ItemGroup Label="ProjectConfigurations"> | |
4 | + <ProjectConfiguration Include="Debug|Win32"> | |
5 | + <Configuration>Debug</Configuration> | |
6 | + <Platform>Win32</Platform> | |
7 | + </ProjectConfiguration> | |
8 | + <ProjectConfiguration Include="Release|Win32"> | |
9 | + <Configuration>Release</Configuration> | |
10 | + <Platform>Win32</Platform> | |
11 | + </ProjectConfiguration> | |
12 | + </ItemGroup> | |
13 | + <PropertyGroup Label="Globals"> | |
14 | + <ProjectGuid>{EE7AE382-8502-4D97-A6AE-3E9504311E7F}</ProjectGuid> | |
15 | + <RootNamespace>DLCardTool</RootNamespace> | |
16 | + <Keyword>MFCProj</Keyword> | |
17 | + </PropertyGroup> | |
18 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |
19 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |
20 | + <ConfigurationType>Application</ConfigurationType> | |
21 | + <UseDebugLibraries>true</UseDebugLibraries> | |
22 | + <PlatformToolset>v120</PlatformToolset> | |
23 | + <CharacterSet>Unicode</CharacterSet> | |
24 | + <UseOfMfc>Static</UseOfMfc> | |
25 | + </PropertyGroup> | |
26 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |
27 | + <ConfigurationType>Application</ConfigurationType> | |
28 | + <UseDebugLibraries>false</UseDebugLibraries> | |
29 | + <PlatformToolset>v120</PlatformToolset> | |
30 | + <WholeProgramOptimization>true</WholeProgramOptimization> | |
31 | + <CharacterSet>Unicode</CharacterSet> | |
32 | + <UseOfMfc>Static</UseOfMfc> | |
33 | + </PropertyGroup> | |
34 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |
35 | + <ImportGroup Label="ExtensionSettings"> | |
36 | + </ImportGroup> | |
37 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
38 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
39 | + </ImportGroup> | |
40 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
41 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
42 | + </ImportGroup> | |
43 | + <PropertyGroup Label="UserMacros" /> | |
44 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
45 | + <LinkIncremental>true</LinkIncremental> | |
46 | + <IncludePath>$(BOOST);$(IncludePath)</IncludePath> | |
47 | + <LibraryPath>$(BOOST)\stage\lib\$(Platform);$(LibraryPath)</LibraryPath> | |
48 | + <TargetName>$(ProjectName)</TargetName> | |
49 | + </PropertyGroup> | |
50 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
51 | + <LinkIncremental>false</LinkIncremental> | |
52 | + <IncludePath>$(BOOST);$(IncludePath)</IncludePath> | |
53 | + <LibraryPath>$(BOOST)\stage\lib\$(Platform);$(CEF_PATH)\$(Configuration);$(CEF_PATH)\out\$(Configuration)\lib;$(ProjectDir)\ExLib\hardware\pin_pad;$(ProjectDir)\ExLib\hardware\pwd_machine;$(ProjectDir)\ExLib\hardware\bank_card_reader;$(LibraryPath)</LibraryPath> | |
54 | + </PropertyGroup> | |
55 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
56 | + <ClCompile> | |
57 | + <PrecompiledHeader>Use</PrecompiledHeader> | |
58 | + <WarningLevel>Level3</WarningLevel> | |
59 | + <Optimization>Disabled</Optimization> | |
60 | + <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
61 | + <SDLCheck> | |
62 | + </SDLCheck> | |
63 | + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | |
64 | + <AdditionalOptions>/FS %(AdditionalOptions)</AdditionalOptions> | |
65 | + <BasicRuntimeChecks>Default</BasicRuntimeChecks> | |
66 | + </ClCompile> | |
67 | + <Link> | |
68 | + <SubSystem>Windows</SubSystem> | |
69 | + <GenerateDebugInformation>true</GenerateDebugInformation> | |
70 | + <AdditionalDependencies>dlcm.lib;union_syj1001_api.lib;Winhttp.lib;DesDLL.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
71 | + <EnableUAC>false</EnableUAC> | |
72 | + </Link> | |
73 | + <Midl> | |
74 | + <MkTypLibCompatible>false</MkTypLibCompatible> | |
75 | + <ValidateAllParameters>true</ValidateAllParameters> | |
76 | + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
77 | + </Midl> | |
78 | + <ResourceCompile> | |
79 | + <Culture>0x0804</Culture> | |
80 | + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
81 | + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
82 | + </ResourceCompile> | |
83 | + </ItemDefinitionGroup> | |
84 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
85 | + <ClCompile> | |
86 | + <WarningLevel>Level3</WarningLevel> | |
87 | + <PrecompiledHeader>Use</PrecompiledHeader> | |
88 | + <Optimization>MaxSpeed</Optimization> | |
89 | + <FunctionLevelLinking>true</FunctionLevelLinking> | |
90 | + <IntrinsicFunctions>true</IntrinsicFunctions> | |
91 | + <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
92 | + <SDLCheck>true</SDLCheck> | |
93 | + <AdditionalOptions>/Zm115 %(AdditionalOptions)</AdditionalOptions> | |
94 | + <AdditionalIncludeDirectories> | |
95 | + </AdditionalIncludeDirectories> | |
96 | + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> | |
97 | + </ClCompile> | |
98 | + <Link> | |
99 | + <SubSystem>Windows</SubSystem> | |
100 | + <GenerateDebugInformation>true</GenerateDebugInformation> | |
101 | + <EnableCOMDATFolding>true</EnableCOMDATFolding> | |
102 | + <OptimizeReferences>true</OptimizeReferences> | |
103 | + <AdditionalDependencies>dlcm.lib;union_syj1001_api.lib;Winhttp.lib;DesDLL.lib;%(AdditionalDependencies)</AdditionalDependencies> | |
104 | + </Link> | |
105 | + <Midl> | |
106 | + <MkTypLibCompatible>false</MkTypLibCompatible> | |
107 | + <ValidateAllParameters>true</ValidateAllParameters> | |
108 | + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
109 | + </Midl> | |
110 | + <ResourceCompile> | |
111 | + <Culture>0x0804</Culture> | |
112 | + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
113 | + <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
114 | + </ResourceCompile> | |
115 | + </ItemDefinitionGroup> | |
116 | + <ItemGroup> | |
117 | + <Text Include="ReadMe.txt" /> | |
118 | + </ItemGroup> | |
119 | + <ItemGroup> | |
120 | + <ClInclude Include="commonCmd.h" /> | |
121 | + <ClInclude Include="DLCardManager.h" /> | |
122 | + <ClInclude Include="DLCardTool.h" /> | |
123 | + <ClInclude Include="DLCardToolDlg.h" /> | |
124 | + <ClInclude Include="DLConfig.h" /> | |
125 | + <ClInclude Include="DLDes.h" /> | |
126 | + <ClInclude Include="DLTools.h" /> | |
127 | + <ClInclude Include="json_parser.hpp" /> | |
128 | + <ClInclude Include="json_parser_write.hpp" /> | |
129 | + <ClInclude Include="mangerCmd.h" /> | |
130 | + <ClInclude Include="openssl_aes_cbc.h" /> | |
131 | + <ClInclude Include="password_machine.h" /> | |
132 | + <ClInclude Include="Resource.h" /> | |
133 | + <ClInclude Include="stdafx.h" /> | |
134 | + <ClInclude Include="string_converter.h" /> | |
135 | + <ClInclude Include="targetver.h" /> | |
136 | + <ClInclude Include="tinystr.h" /> | |
137 | + <ClInclude Include="tinyxml.h" /> | |
138 | + <ClInclude Include="win_http.h" /> | |
139 | + </ItemGroup> | |
140 | + <ItemGroup> | |
141 | + <ClCompile Include="DLCardTool.cpp" /> | |
142 | + <ClCompile Include="DLCardToolDlg.cpp" /> | |
143 | + <ClCompile Include="DLConfig.cpp" /> | |
144 | + <ClCompile Include="DLTools.cpp"> | |
145 | + <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
146 | + </ClCompile> | |
147 | + <ClCompile Include="openssl_aes_cbc.cpp" /> | |
148 | + <ClCompile Include="password_machine.cpp" /> | |
149 | + <ClCompile Include="stdafx.cpp"> | |
150 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | |
151 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | |
152 | + </ClCompile> | |
153 | + <ClCompile Include="string_converter.cpp" /> | |
154 | + <ClCompile Include="tinystr.cpp" /> | |
155 | + <ClCompile Include="tinyxml.cpp" /> | |
156 | + <ClCompile Include="tinyxmlerror.cpp" /> | |
157 | + <ClCompile Include="tinyxmlparser.cpp" /> | |
158 | + <ClCompile Include="win_http.cpp" /> | |
159 | + </ItemGroup> | |
160 | + <ItemGroup> | |
161 | + <ResourceCompile Include="DLCardTool.rc" /> | |
162 | + </ItemGroup> | |
163 | + <ItemGroup> | |
164 | + <None Include="res\DLCardTool.rc2" /> | |
165 | + </ItemGroup> | |
166 | + <ItemGroup> | |
167 | + <Image Include="DLLogo.ico" /> | |
168 | + <Image Include="res\DLCardTool.ico" /> | |
169 | + <Image Include="res\DLLogo.ico" /> | |
170 | + </ItemGroup> | |
171 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |
172 | + <ImportGroup Label="ExtensionTargets"> | |
173 | + </ImportGroup> | |
174 | + <ProjectExtensions> | |
175 | + <VisualStudio> | |
176 | + <UserProperties RESOURCE_FILE="DLCardTool.rc" /> | |
177 | + </VisualStudio> | |
178 | + </ProjectExtensions> | |
179 | +</Project> | |
0 | 180 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLCardTool.vcxproj.filters
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
3 | + <ItemGroup> | |
4 | + <Filter Include="源文件"> | |
5 | + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |
6 | + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |
7 | + </Filter> | |
8 | + <Filter Include="头文件"> | |
9 | + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |
10 | + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | |
11 | + </Filter> | |
12 | + <Filter Include="资源文件"> | |
13 | + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |
14 | + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |
15 | + </Filter> | |
16 | + </ItemGroup> | |
17 | + <ItemGroup> | |
18 | + <Text Include="ReadMe.txt" /> | |
19 | + </ItemGroup> | |
20 | + <ItemGroup> | |
21 | + <ClInclude Include="DLCardTool.h"> | |
22 | + <Filter>头文件</Filter> | |
23 | + </ClInclude> | |
24 | + <ClInclude Include="DLCardToolDlg.h"> | |
25 | + <Filter>头文件</Filter> | |
26 | + </ClInclude> | |
27 | + <ClInclude Include="stdafx.h"> | |
28 | + <Filter>头文件</Filter> | |
29 | + </ClInclude> | |
30 | + <ClInclude Include="targetver.h"> | |
31 | + <Filter>头文件</Filter> | |
32 | + </ClInclude> | |
33 | + <ClInclude Include="Resource.h"> | |
34 | + <Filter>头文件</Filter> | |
35 | + </ClInclude> | |
36 | + <ClInclude Include="DLCardManager.h"> | |
37 | + <Filter>头文件</Filter> | |
38 | + </ClInclude> | |
39 | + <ClInclude Include="DLTools.h"> | |
40 | + <Filter>头文件</Filter> | |
41 | + </ClInclude> | |
42 | + <ClInclude Include="openssl_aes_cbc.h"> | |
43 | + <Filter>头文件</Filter> | |
44 | + </ClInclude> | |
45 | + <ClInclude Include="string_converter.h"> | |
46 | + <Filter>头文件</Filter> | |
47 | + </ClInclude> | |
48 | + <ClInclude Include="password_machine.h"> | |
49 | + <Filter>头文件</Filter> | |
50 | + </ClInclude> | |
51 | + <ClInclude Include="tinyxml.h"> | |
52 | + <Filter>头文件</Filter> | |
53 | + </ClInclude> | |
54 | + <ClInclude Include="commonCmd.h"> | |
55 | + <Filter>头文件</Filter> | |
56 | + </ClInclude> | |
57 | + <ClInclude Include="mangerCmd.h"> | |
58 | + <Filter>头文件</Filter> | |
59 | + </ClInclude> | |
60 | + <ClInclude Include="tinystr.h"> | |
61 | + <Filter>头文件</Filter> | |
62 | + </ClInclude> | |
63 | + <ClInclude Include="win_http.h"> | |
64 | + <Filter>头文件</Filter> | |
65 | + </ClInclude> | |
66 | + <ClInclude Include="json_parser.hpp"> | |
67 | + <Filter>头文件</Filter> | |
68 | + </ClInclude> | |
69 | + <ClInclude Include="json_parser_write.hpp"> | |
70 | + <Filter>头文件</Filter> | |
71 | + </ClInclude> | |
72 | + <ClInclude Include="DLDes.h"> | |
73 | + <Filter>头文件</Filter> | |
74 | + </ClInclude> | |
75 | + <ClInclude Include="DLConfig.h"> | |
76 | + <Filter>头文件</Filter> | |
77 | + </ClInclude> | |
78 | + </ItemGroup> | |
79 | + <ItemGroup> | |
80 | + <ClCompile Include="DLCardTool.cpp"> | |
81 | + <Filter>源文件</Filter> | |
82 | + </ClCompile> | |
83 | + <ClCompile Include="DLCardToolDlg.cpp"> | |
84 | + <Filter>源文件</Filter> | |
85 | + </ClCompile> | |
86 | + <ClCompile Include="stdafx.cpp"> | |
87 | + <Filter>源文件</Filter> | |
88 | + </ClCompile> | |
89 | + <ClCompile Include="DLTools.cpp"> | |
90 | + <Filter>源文件</Filter> | |
91 | + </ClCompile> | |
92 | + <ClCompile Include="openssl_aes_cbc.cpp"> | |
93 | + <Filter>源文件</Filter> | |
94 | + </ClCompile> | |
95 | + <ClCompile Include="string_converter.cpp"> | |
96 | + <Filter>源文件</Filter> | |
97 | + </ClCompile> | |
98 | + <ClCompile Include="password_machine.cpp"> | |
99 | + <Filter>源文件</Filter> | |
100 | + </ClCompile> | |
101 | + <ClCompile Include="tinyxml.cpp"> | |
102 | + <Filter>源文件</Filter> | |
103 | + </ClCompile> | |
104 | + <ClCompile Include="tinystr.cpp"> | |
105 | + <Filter>源文件</Filter> | |
106 | + </ClCompile> | |
107 | + <ClCompile Include="tinyxmlerror.cpp"> | |
108 | + <Filter>源文件</Filter> | |
109 | + </ClCompile> | |
110 | + <ClCompile Include="tinyxmlparser.cpp"> | |
111 | + <Filter>源文件</Filter> | |
112 | + </ClCompile> | |
113 | + <ClCompile Include="win_http.cpp"> | |
114 | + <Filter>源文件</Filter> | |
115 | + </ClCompile> | |
116 | + <ClCompile Include="DLConfig.cpp"> | |
117 | + <Filter>源文件</Filter> | |
118 | + </ClCompile> | |
119 | + </ItemGroup> | |
120 | + <ItemGroup> | |
121 | + <ResourceCompile Include="DLCardTool.rc"> | |
122 | + <Filter>资源文件</Filter> | |
123 | + </ResourceCompile> | |
124 | + </ItemGroup> | |
125 | + <ItemGroup> | |
126 | + <None Include="res\DLCardTool.rc2"> | |
127 | + <Filter>资源文件</Filter> | |
128 | + </None> | |
129 | + </ItemGroup> | |
130 | + <ItemGroup> | |
131 | + <Image Include="res\DLCardTool.ico"> | |
132 | + <Filter>资源文件</Filter> | |
133 | + </Image> | |
134 | + <Image Include="DLLogo.ico"> | |
135 | + <Filter>资源文件</Filter> | |
136 | + </Image> | |
137 | + <Image Include="res\DLLogo.ico"> | |
138 | + <Filter>资源文件</Filter> | |
139 | + </Image> | |
140 | + </ItemGroup> | |
141 | +</Project> | |
0 | 142 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLCardToolDlg.cpp
0 → 100644
1 | + | |
2 | +// DLCardToolDlg.cpp : 实现文件 | |
3 | +// | |
4 | + | |
5 | +#include "stdafx.h" | |
6 | +#include "DLCardTool.h" | |
7 | +#include "DLCardToolDlg.h" | |
8 | +#include "afxdialogex.h" | |
9 | +#include <vector> | |
10 | +#include "password_machine.h" | |
11 | +#include "win_http.h" | |
12 | +#include "DLDes.h" | |
13 | +#include <boost/filesystem.hpp> | |
14 | + | |
15 | + | |
16 | +#ifdef _DEBUG | |
17 | +#define new DEBUG_NEW | |
18 | +#endif | |
19 | + | |
20 | + | |
21 | +static const char* MF_FILE_DIR = "3F00"; | |
22 | +static const char* DF01_DIR = "DF01"; | |
23 | + | |
24 | +static const char BASIC_INFO_FILE_ID = 0x5; | |
25 | +static const char SERVICE_INFO_FILE_ID = 0x15; | |
26 | + | |
27 | +static const char* K_DCCK_DV = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0"; | |
28 | +static const char* K_F0015_DACK_DV = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6"; | |
29 | +static const char* K_F0015_DEAK_DV = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7"; | |
30 | +static const char* K_F0015_DAMK1_DV = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8"; | |
31 | + | |
32 | +static const char* K_F0005_DCMK1 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4"; | |
33 | + | |
34 | + | |
35 | +const CString kSuccessText = L"升级成功!"; | |
36 | +const CString kFailedText = L"升级失败!"; | |
37 | +const CString kNotNeedUpdate = L"卡片是最新配置,无需升级。"; | |
38 | + | |
39 | +// CDLCardToolDlg 对话框 | |
40 | + | |
41 | + | |
42 | + | |
43 | +CDLCardToolDlg::CDLCardToolDlg(CWnd* pParent /*=NULL*/) | |
44 | + : CDialogEx(CDLCardToolDlg::IDD, pParent), m_bSetRed(false) | |
45 | +{ | |
46 | + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); | |
47 | +} | |
48 | + | |
49 | +void CDLCardToolDlg::DoDataExchange(CDataExchange* pDX) | |
50 | +{ | |
51 | + CDialogEx::DoDataExchange(pDX); | |
52 | + //DDX_Control(pDX, IDC_RICHEDIT_NOTICE, m_cNotice); | |
53 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN, m_cExplain); | |
54 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN1, m_cExplain1); | |
55 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN2, m_cExplain2); | |
56 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN3, m_cExplain3); | |
57 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN4, m_cExplain4); | |
58 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN5, m_cExplain5); | |
59 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN6, m_cExplain6); | |
60 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN7, m_cExplain7); | |
61 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN8, m_cExplain8); | |
62 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN9, m_cExplain9); | |
63 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN10, m_cExplain10); | |
64 | + DDX_Control(pDX, IDC_STATIC_EXPLAIN11, m_cExplain11); | |
65 | + DDX_Control(pDX, IDC_BUTTON_CARDUPDATE, m_cUpdateButton); | |
66 | + DDX_Control(pDX, IDC_STATIC_CARDNUM, m_cStaticCardNum); | |
67 | + DDX_Control(pDX, IDC_STATIC_CARD_NUM_TEXT, m_cStaticCardNumText); | |
68 | + DDX_Control(pDX, IDC_STATIC_RESULT, m_cResult); | |
69 | + DDX_Control(pDX, IDC_STATIC_RESULT_TEXT, m_cResultText); | |
70 | + DDX_Control(pDX, IDC_STATIC_IMG, m_cStaticImg); | |
71 | + DDX_Control(pDX, IDC_STATIC_RESULT2, m_cResultText2); | |
72 | +} | |
73 | + | |
74 | +BEGIN_MESSAGE_MAP(CDLCardToolDlg, CDialogEx) | |
75 | + ON_WM_PAINT() | |
76 | + ON_WM_QUERYDRAGICON() | |
77 | + ON_BN_CLICKED(IDC_BUTTON_CARDUPDATE, &CDLCardToolDlg::OnBnClickedButtonCardupdate) | |
78 | + ON_WM_CTLCOLOR() | |
79 | +END_MESSAGE_MAP() | |
80 | + | |
81 | + | |
82 | +// CDLCardToolDlg 消息处理程序 | |
83 | + | |
84 | +BOOL CDLCardToolDlg::OnInitDialog() | |
85 | +{ | |
86 | + CDialogEx::OnInitDialog(); | |
87 | + | |
88 | + // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 | |
89 | + // 执行此操作 | |
90 | + SetIcon(m_hIcon, TRUE); // 设置大图标 | |
91 | + SetIcon(m_hIcon, FALSE); // 设置小图标 | |
92 | + | |
93 | + | |
94 | + SetWindowText(L"地利卡片升级工具"); | |
95 | + CRect rtDlg; | |
96 | + rtDlg.top = rtDlg.left = 0; | |
97 | + //保持黄金比例,完美! | |
98 | + rtDlg.bottom = 600; | |
99 | + rtDlg.right = 616; | |
100 | + MoveWindow(&rtDlg); | |
101 | + | |
102 | + m_cConfig.ReadConfig(); | |
103 | + | |
104 | + SetCtrlText(); | |
105 | + SetCtrlImg(); | |
106 | + SetCtrlFont(); | |
107 | + ResizeCtrl(); | |
108 | + | |
109 | + Invalidate(TRUE);// 重绘界面,解决界面控件显示不全的问题 | |
110 | + | |
111 | + return TRUE; // 除非将焦点设置到控件,否则返回 TRUE | |
112 | +} | |
113 | + | |
114 | +// 如果向对话框添加最小化按钮,则需要下面的代码 | |
115 | +// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序, | |
116 | +// 这将由框架自动完成。 | |
117 | + | |
118 | +void CDLCardToolDlg::OnPaint() | |
119 | +{ | |
120 | + CPaintDC dc(this); // 用于绘制的设备上下文 | |
121 | + CPen *pOldPen = dc.SelectObject(&m_cPen);//保存DC原始画笔 | |
122 | + | |
123 | + CRect rtExplain; | |
124 | + m_cExplain9.GetWindowRect(&rtExplain); | |
125 | + CRect rtPanel; | |
126 | + GetClientRect(&rtPanel); | |
127 | + | |
128 | + dc.MoveTo(26, rtExplain.bottom + 24); //设置DC当前点 | |
129 | + dc.LineTo(rtPanel.right - 26, rtExplain.bottom + 24); //绘制直线 | |
130 | + dc.SelectObject(pOldPen); //回复DC原画笔 | |
131 | + | |
132 | + if (IsIconic()) | |
133 | + { | |
134 | + CPaintDC dc(this); // 用于绘制的设备上下文 | |
135 | + | |
136 | + SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); | |
137 | + | |
138 | + // 使图标在工作区矩形中居中 | |
139 | + int cxIcon = GetSystemMetrics(SM_CXICON); | |
140 | + int cyIcon = GetSystemMetrics(SM_CYICON); | |
141 | + CRect rect; | |
142 | + GetClientRect(&rect); | |
143 | + int x = (rect.Width() - cxIcon + 1) / 2; | |
144 | + int y = (rect.Height() - cyIcon + 1) / 2; | |
145 | + | |
146 | + // 绘制图标 | |
147 | + dc.DrawIcon(x, y, m_hIcon); | |
148 | + } | |
149 | + else | |
150 | + { | |
151 | + CDialogEx::OnPaint(); | |
152 | + } | |
153 | +} | |
154 | + | |
155 | +//当用户拖动最小化窗口时系统调用此函数取得光标 | |
156 | +//显示。 | |
157 | +HCURSOR CDLCardToolDlg::OnQueryDragIcon() | |
158 | +{ | |
159 | + return static_cast<HCURSOR>(m_hIcon); | |
160 | +} | |
161 | + | |
162 | +template <typename T> | |
163 | +std::string DecToHex(T d, bool show_base = false) | |
164 | +{ | |
165 | + std::stringstream ss; | |
166 | + if (show_base) | |
167 | + ss << "0x"; | |
168 | + ss << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex << static_cast<int>(d); | |
169 | + return ss.str(); | |
170 | +} | |
171 | + | |
172 | +void CDLCardToolDlg::OnBnClickedButtonCardupdate() | |
173 | +{ | |
174 | + SetMsgLog(L"卡片升级。"); | |
175 | + | |
176 | + int iErrorCode = 0; | |
177 | + bool bSuccess = true; | |
178 | + do | |
179 | + { | |
180 | + SetMsgLog(L"连接读卡器。"); | |
181 | + iErrorCode = DLCConnectDevice(); | |
182 | + if (iErrorCode) | |
183 | + { | |
184 | + SetMsgLog(L"打开读卡器失败!", LOG_ERROR, iErrorCode); | |
185 | + SetResultTest(kFailedText, L"原因:打开读卡器失败!"); | |
186 | + bSuccess = false; | |
187 | + break; | |
188 | + } | |
189 | + | |
190 | + SetMsgLog(L"寻找卡片。"); | |
191 | + iErrorCode = DLCFindCard(); | |
192 | + if (iErrorCode) | |
193 | + { | |
194 | + SetMsgLog(L"寻卡失败!", LOG_ERROR, iErrorCode); | |
195 | + SetResultTest(kFailedText, L"原因:寻卡失败!"); | |
196 | + bSuccess = false; | |
197 | + break; | |
198 | + } | |
199 | + | |
200 | + SetMsgLog(L"读取基本信息。"); | |
201 | + BasicInfo biCardInfo; | |
202 | + try | |
203 | + { | |
204 | + biCardInfo = ReadBasicInfo(); | |
205 | + } | |
206 | + catch (std::exception &ex) | |
207 | + { | |
208 | + std::string sError = ex.what(); | |
209 | + SetMsgLog(L"读取卡片基本信息失败!", LOG_ERROR, atoi(sError.c_str())); | |
210 | + SetResultTest(kFailedText, L"原因:读取卡片基本信息失败!"); | |
211 | + bSuccess = false; | |
212 | + break; | |
213 | + } | |
214 | + | |
215 | + SetMsgLog(CString("卡号:") + str_2_wstr(biCardInfo.sCardNum).c_str()); | |
216 | + | |
217 | + SetMsgLog(L"查询卡片状态。"); | |
218 | + CardStateInfo csiCardStateInfo; | |
219 | + csiCardStateInfo = CheckCardState(biCardInfo); | |
220 | + | |
221 | + m_cStaticCardNumText.SetWindowTextW(str_2_wstr(biCardInfo.sCardNum).c_str()); | |
222 | + | |
223 | + | |
224 | + if (csiCardStateInfo.bAlreadyUpdate) | |
225 | + { | |
226 | + SetMsgLog(kNotNeedUpdate, LOG_ERROR); | |
227 | + SetResultTest(kNotNeedUpdate, L""); | |
228 | + bSuccess = false; | |
229 | + break; | |
230 | + } | |
231 | + | |
232 | + SetMsgLog(L"获取主控秘钥。"); | |
233 | + std::string sMainDCCK; | |
234 | + try | |
235 | + { | |
236 | + GetMainKey(m_cConfig.m_bUsePWM, biCardInfo.sCardOldSn, sMainDCCK); | |
237 | + } | |
238 | + catch (std::exception &ex) | |
239 | + { | |
240 | + std::string sError = ex.what(); | |
241 | + SetMsgLog(str_2_wstr(sError).c_str(), LOG_ERROR); | |
242 | + SetResultTest(kFailedText, L"获取主控秘钥失败!"); | |
243 | + bSuccess = false; | |
244 | + break; | |
245 | + } | |
246 | + | |
247 | + unsigned char aucSize[4] = { 0 }; | |
248 | + memcpy(aucSize, "0324", 4); | |
249 | + iErrorCode = DLCCreateFile((const unsigned char*)"3f00", (const unsigned char*)sMainDCCK.c_str(), (const unsigned char*)"df20", NULL, 1); | |
250 | + if (iErrorCode) | |
251 | + { | |
252 | + SetMsgLog(CString("创建文件夹失败!错误码:" + iErrorCode), LOG_ERROR); | |
253 | + SetResultTest(kFailedText, L"创建文件夹失败!"); | |
254 | + bSuccess = false; | |
255 | + break; | |
256 | + } | |
257 | + | |
258 | + iErrorCode = DLCCreateFile((const unsigned char*)"df20", (const unsigned char*)sMainDCCK.c_str(), (const unsigned char*)"0025", aucSize, 3); | |
259 | + if (iErrorCode) | |
260 | + { | |
261 | + SetMsgLog(CString("创建文件失败!错误码:" + iErrorCode), LOG_ERROR); | |
262 | + SetResultTest(kFailedText, L"创建文件失败!"); | |
263 | + bSuccess = false; | |
264 | + break; | |
265 | + } | |
266 | + memcpy(aucSize, "0709", 4); | |
267 | + iErrorCode = DLCCreateFile((const unsigned char*)"df20", (const unsigned char*)sMainDCCK.c_str(), (const unsigned char*)"0026", aucSize, 3); | |
268 | + if (iErrorCode) | |
269 | + { | |
270 | + SetMsgLog(CString("创建文件失败!错误码:" + iErrorCode), LOG_ERROR); | |
271 | + SetResultTest(kFailedText, L"创建文件失败!"); | |
272 | + bSuccess = false; | |
273 | + break; | |
274 | + } | |
275 | + | |
276 | + } while (0); | |
277 | + | |
278 | + SetMsgLog(L"关闭读卡器。"); | |
279 | + DLCDisconnectDevice(); | |
280 | + | |
281 | + if (bSuccess) | |
282 | + { | |
283 | + SetMsgLog(L"升级成功!", LOG_ERROR); | |
284 | + SetResultTest(kSuccessText, L""); | |
285 | + } | |
286 | +} | |
287 | + | |
288 | + | |
289 | +void CDLCardToolDlg::GetMainKey(bool bUsePWM, std::string sSN, std::string &sDCCK) | |
290 | +{ | |
291 | + | |
292 | + if (bUsePWM) | |
293 | + { | |
294 | + sDCCK = m_cPWDMachine.GetPassword("0000", sSN, 10000, m_cConfig.m_sPWMIP, m_cConfig.m_u32PWMPort); | |
295 | + } | |
296 | + else | |
297 | + { | |
298 | + sDCCK = K_DCCK_DV; | |
299 | + } | |
300 | +} | |
301 | + | |
302 | +void CDLCardToolDlg::SetMsgLog(CString sText, LOG_TYPE emLogType /*= LOG_TRACE*/, int iErrorCode /*= 0*/) | |
303 | +{ | |
304 | + CString sErrorCode; | |
305 | + if (iErrorCode) | |
306 | + { | |
307 | + sErrorCode.Format(L",错误码: %d", iErrorCode); | |
308 | + } | |
309 | + CString sLogType = emLogType == LOG_TRACE ? L"<trace> " : L"<error> "; | |
310 | + | |
311 | + Log(sLogType + sText + sErrorCode); | |
312 | +} | |
313 | + | |
314 | +HBRUSH CDLCardToolDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) | |
315 | +{ | |
316 | + HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); | |
317 | + | |
318 | + if (pWnd == &m_cExplain2 || pWnd == &m_cExplain4) | |
319 | + { | |
320 | + pDC->SetTextColor(RGB(236, 72, 34)); | |
321 | + } | |
322 | + else if (pWnd == &m_cExplain10) | |
323 | + { | |
324 | + pDC->SetTextColor(RGB(223, 78, 33)); | |
325 | + } | |
326 | + else if (pWnd == &m_cExplain || pWnd == &m_cExplain6 || pWnd == &m_cExplain8 | |
327 | + || pWnd == &m_cExplain9 || pWnd == &m_cExplain11 || pWnd == &m_cStaticCardNum | |
328 | + || pWnd == &m_cResult) | |
329 | + { | |
330 | + pDC->SetTextColor(RGB(102, 102, 102)); | |
331 | + } | |
332 | + else if (pWnd == &m_cExplain1 || pWnd == &m_cExplain3 || pWnd == &m_cExplain5) | |
333 | + { | |
334 | + pDC->SetTextColor(RGB(51, 51, 51)); | |
335 | + } | |
336 | + else if (pWnd == &m_cExplain7) | |
337 | + { | |
338 | + pDC->SetTextColor(RGB(47, 166, 35)); | |
339 | + } | |
340 | + else if (pWnd == &m_cResultText && m_bSetRed) | |
341 | + { | |
342 | + pDC->SetTextColor(RGB(223, 78, 33)); | |
343 | + m_bSetRed = false; | |
344 | + } | |
345 | + | |
346 | + return hbr; | |
347 | +} | |
348 | + | |
349 | +CardStateInfo CDLCardToolDlg::CheckCardState(BasicInfo biCardInfo) | |
350 | +{ | |
351 | + CardStateInfo stuCardState; | |
352 | + | |
353 | + std::string sDCCK; | |
354 | + | |
355 | + if (m_cConfig.m_bUsePWM) | |
356 | + { | |
357 | + sDCCK = m_cPWDMachine.GetPassword("0000", biCardInfo.sCardOldSn, 10000, m_cConfig.m_sPWMIP, m_cConfig.m_u32PWMPort); | |
358 | + } | |
359 | + else | |
360 | + { | |
361 | + sDCCK = std::string("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0"); | |
362 | + } | |
363 | + | |
364 | + if (!DLCSelectFile((unsigned char*)"df20")) | |
365 | + { | |
366 | + stuCardState.bAlreadyUpdate = true; | |
367 | + } | |
368 | + else | |
369 | + { | |
370 | + stuCardState.bAlreadyUpdate = false; | |
371 | + } | |
372 | + | |
373 | + return stuCardState; | |
374 | +} | |
375 | + | |
376 | +//CardStateInfo CDLCardToolDlg::ReadJson(CString sResponseBody) | |
377 | +//{ | |
378 | +// CardStateInfo stuServiceData; | |
379 | +// | |
380 | +// static const std::string JSON_TAG_STATUS = "status"; | |
381 | +// static const std::string JSON_TAG_SECRETSTR = "secretStr"; | |
382 | +// | |
383 | +// static const std::string JSON_VAL_UNSTORAGE = "0"; | |
384 | +// static const std::string JSON_VAL_STORAGE = "1"; | |
385 | +// static const std::string JSON_VAL_USE = "2"; | |
386 | +// | |
387 | +// namespace PT = boost::property_tree; | |
388 | +// bool login_res = false; | |
389 | +// try //Parse the configuration file | |
390 | +// { | |
391 | +// PT::ptree ptree; | |
392 | +// std::stringstream ss; | |
393 | +// ss << wstr_2_str(sResponseBody); | |
394 | +// PT::read_json(ss, ptree); | |
395 | +// std::string sStatus = ptree.get<std::string>(JSON_TAG_STATUS); | |
396 | +// if (sStatus.compare(JSON_VAL_UNSTORAGE) == 0) | |
397 | +// { | |
398 | +// stuServiceData.csCardState = CS_UNSTORAGE; | |
399 | +// } | |
400 | +// else if (sStatus.compare(JSON_VAL_STORAGE) == 0) | |
401 | +// { | |
402 | +// stuServiceData.csCardState = CS_STORAGE; | |
403 | +// } | |
404 | +// else if (sStatus.compare(JSON_VAL_USE) == 0) | |
405 | +// { | |
406 | +// stuServiceData.csCardState = CS_USE; | |
407 | +// stuServiceData.sServiceData = ptree.get<std::string>(JSON_TAG_SECRETSTR).c_str(); | |
408 | +// } | |
409 | +// | |
410 | +// | |
411 | +// } | |
412 | +// catch (...) | |
413 | +// { | |
414 | +// throw std::exception("解析服务器返回的信息时出错!请确认返回数据不为空,返回的数据格式为正确的Json格式!", LOG_ERROR); | |
415 | +// } | |
416 | +// | |
417 | +// return stuServiceData; | |
418 | +//} | |
419 | + | |
420 | +BasicInfo CDLCardToolDlg::ReadBasicInfo() | |
421 | +{ | |
422 | + BasicInfo biCardBasicInfo; | |
423 | + | |
424 | + unsigned char aucDirMF[4] = { 0 }; | |
425 | + unsigned char aucCardBasicInfo[88] = { 0 }; | |
426 | + memcpy(aucDirMF, MF_FILE_DIR, 4); | |
427 | + int iErrorCode = DLCReadCardData(aucDirMF, BASIC_INFO_FILE_ID, 0, 88, NULL, aucCardBasicInfo); //实际上取出了所有基本信息 | |
428 | + | |
429 | + std::string sCardnum((char *)aucCardBasicInfo, 0, 12); | |
430 | + std::string sOldSn((char*)aucCardBasicInfo, 56, 88); | |
431 | + | |
432 | + biCardBasicInfo.sCardNum = sCardnum; | |
433 | + biCardBasicInfo.sCardOldSn = sOldSn; | |
434 | + | |
435 | + return biCardBasicInfo; | |
436 | +} | |
437 | + | |
438 | +//std::string CDLCardToolDlg::CalculateKey(BasicInfo biCardBasicInfo, KEY_TYPE ktKeyType, int iEncryptType) | |
439 | +//{ | |
440 | +// std::string sNewKey; | |
441 | +// if (iEncryptType == 0) | |
442 | +// { | |
443 | +// std::string sKeyType; | |
444 | +// switch (ktKeyType) | |
445 | +// { | |
446 | +// case KT_DACK: | |
447 | +// case KT_DCCK: | |
448 | +// { | |
449 | +// sKeyType = "0000"; | |
450 | +// break; | |
451 | +// } | |
452 | +// case KT_DEAK: | |
453 | +// { | |
454 | +// sKeyType = "0001"; | |
455 | +// break; | |
456 | +// } | |
457 | +// case KT_DAMK: | |
458 | +// { | |
459 | +// sKeyType = "0002"; | |
460 | +// break; | |
461 | +// } | |
462 | +// } | |
463 | +// sNewKey = m_cPWDMachine.GetPassword(sKeyType, biCardBasicInfo.sC, 10000, m_cConfig.m_sPWMIP, m_cConfig.m_u32PWMPort); | |
464 | +// } | |
465 | +// else | |
466 | +// { | |
467 | +// const char* pDCCKDL = "43434bff43434bff"; | |
468 | +// const char* pDACKDL = "41434bff41434bff"; | |
469 | +// const char* pDEAKDL = "45414bff45414bff"; | |
470 | +// const char* pDAMKDL = "414d4b31414d4b31"; | |
471 | +// | |
472 | +// unsigned char aucCardSNHex[16] = { 0 }; | |
473 | +// unsigned char aucDCCKDL[8] = { 0 }, aucDACKDL[8] = { 0 }, aucDEAKDL[8] = { 0 }, aucDAMKDL[8] = { 0 }; | |
474 | +// StringToHex((unsigned char*)pDCCKDL, 16, aucDCCKDL); | |
475 | +// StringToHex((unsigned char*)pDACKDL, 16, aucDACKDL); | |
476 | +// StringToHex((unsigned char*)pDEAKDL, 16, aucDEAKDL); | |
477 | +// StringToHex((unsigned char*)pDAMKDL, 16, aucDAMKDL); | |
478 | +// StringToHex((unsigned char*)biCardBasicInfo.sCardNewSn.c_str(), 32, aucCardSNHex); | |
479 | +// | |
480 | +// unsigned char aucNewKeyHex[16] = { 0 }, aucNewKey[32] = { 0 }; | |
481 | +// | |
482 | +// switch (ktKeyType) | |
483 | +// { | |
484 | +// case KT_DCCK: | |
485 | +// { | |
486 | +// Encrypt(aucCardSNHex, 16, aucDCCKDL, aucNewKeyHex); | |
487 | +// break; | |
488 | +// } | |
489 | +// case KT_DACK: | |
490 | +// { | |
491 | +// Encrypt(aucCardSNHex, 16, aucDACKDL, aucNewKeyHex); | |
492 | +// break; | |
493 | +// } | |
494 | +// case KT_DEAK: | |
495 | +// { | |
496 | +// Encrypt(aucCardSNHex, 16, aucDEAKDL, aucNewKeyHex); | |
497 | +// break; | |
498 | +// } | |
499 | +// case KT_DAMK: | |
500 | +// { | |
501 | +// Encrypt(aucCardSNHex, 16, aucDAMKDL, aucNewKeyHex); | |
502 | +// break; | |
503 | +// } | |
504 | +// } | |
505 | +// | |
506 | +// HexToChar(aucNewKeyHex, 16, aucNewKey); | |
507 | +// std::string sKey((char*)aucNewKey, 32); | |
508 | +// sNewKey = sKey; | |
509 | +// } | |
510 | +// | |
511 | +// | |
512 | +// return sNewKey; | |
513 | +//} | |
514 | + | |
515 | +//void CDLCardToolDlg::InstallKey(std::string sDir, std::string sNewKey, std::string sMainKey, KEY_TYPE ktKeyType, int iKeyID) | |
516 | +//{ | |
517 | +// int iErrorCode = 0; | |
518 | +// | |
519 | +// iErrorCode = InstallDLKey((unsigned char*)sDir.c_str(), iKeyID, (unsigned char*)sNewKey.c_str(), ktKeyType, (unsigned char*)sMainKey.c_str()); | |
520 | +// if (iErrorCode) | |
521 | +// { | |
522 | +// std::stringstream ssErrorCode; | |
523 | +// ssErrorCode << iErrorCode; | |
524 | +// std::string sErrorCode = ssErrorCode.str(); | |
525 | +// throw std::exception(ssErrorCode.str().c_str()); | |
526 | +// } | |
527 | +//} | |
528 | + | |
529 | +//void CDLCardToolDlg::WriteData(std::string sDir, int iFileID, int iOffest, int iLen, std::string sKey, std::string sData) | |
530 | +//{ | |
531 | +// unsigned char aucDir[2] = { 0 }, aucKey[16] = { 0 }; | |
532 | +// | |
533 | +// int iError = WriteDLCardData((unsigned char*)sDir.c_str(), iFileID, iOffest, iLen, (unsigned char*)sData.c_str(), (unsigned char*)sKey.c_str()); | |
534 | +// if (iError) | |
535 | +// { | |
536 | +// | |
537 | +// std::stringstream ssErrorCode; | |
538 | +// ssErrorCode << iError; | |
539 | +// throw std::exception(ssErrorCode.str().c_str()); | |
540 | +// } | |
541 | +//} | |
542 | + | |
543 | + | |
544 | + | |
545 | +void CDLCardToolDlg::ResizeCtrl() | |
546 | +{ | |
547 | + const int kLeftStage = 26; | |
548 | + const int kBmgLenth = 16; | |
549 | + const int kUpStage = 24; | |
550 | + | |
551 | + CRect rtPanel; | |
552 | + GetClientRect(&rtPanel); | |
553 | + | |
554 | + const int kExplainHeight = 20; | |
555 | + const int kEcplainHeightBig = 25; | |
556 | + const int kExplainWidth = 16; | |
557 | + const int kExplainWidthBig = 20; | |
558 | + | |
559 | + CRect rtExplain; | |
560 | + rtExplain.top = kUpStage; | |
561 | + rtExplain.left = kLeftStage + kBmgLenth; | |
562 | + rtExplain.right = rtPanel.right; | |
563 | + rtExplain.bottom = kUpStage + kEcplainHeightBig; | |
564 | + m_cExplain.MoveWindow(&rtExplain); | |
565 | + | |
566 | + CRect rtImg = rtExplain; | |
567 | + rtImg.left = rtExplain.left - kEcplainHeightBig; | |
568 | + rtImg.right = rtExplain.left; | |
569 | + m_cStaticImg.MoveWindow(&rtImg); | |
570 | + | |
571 | + | |
572 | + CRect rtExplain1; | |
573 | + rtExplain1.top = rtExplain.bottom + 24; | |
574 | + rtExplain1.left = rtExplain.left + 24; | |
575 | + rtExplain1.bottom = rtExplain1.top + kEcplainHeightBig; | |
576 | + rtExplain1.right = rtExplain1.left + kExplainWidthBig; | |
577 | + m_cExplain1.MoveWindow(&rtExplain1); | |
578 | + | |
579 | + CRect rtExplain2 = rtExplain1; | |
580 | + rtExplain2.left = rtExplain1.right; | |
581 | + rtExplain2.right = rtExplain2.left + kExplainWidthBig * 9; | |
582 | + m_cExplain2.MoveWindow(&rtExplain2); | |
583 | + | |
584 | + CRect rtExplain3 = rtExplain2; | |
585 | + rtExplain3.left = rtExplain2.right; | |
586 | + rtExplain3.right = rtExplain3.left + kExplainWidthBig * 2; | |
587 | + m_cExplain3.MoveWindow(&rtExplain3); | |
588 | + | |
589 | + CRect rtExplain4 = rtExplain3; | |
590 | + rtExplain4.left = rtExplain3.right; | |
591 | + rtExplain4.right = rtExplain4.left + kExplainWidthBig * 7; | |
592 | + m_cExplain4.MoveWindow(&rtExplain4); | |
593 | + | |
594 | + CRect rtExplain5 = rtExplain4; | |
595 | + rtExplain5.left = rtExplain4.right; | |
596 | + rtExplain5.right = rtExplain5.left + kExplainWidthBig * 7; | |
597 | + m_cExplain5.MoveWindow(&rtExplain5); | |
598 | + | |
599 | + CRect rtExplain6 = rtExplain1; | |
600 | + rtExplain6.top = rtExplain6.bottom + 24; | |
601 | + rtExplain6.bottom = rtExplain6.top + kExplainHeight; | |
602 | + rtExplain6.right = rtExplain6.left + kExplainWidth * 6; | |
603 | + m_cExplain6.MoveWindow(&rtExplain6); | |
604 | + | |
605 | + CRect rtExplain7 = rtExplain6; | |
606 | + rtExplain7.left = rtExplain6.right; | |
607 | + rtExplain7.right = rtExplain7.left + kExplainWidth * 5; | |
608 | + m_cExplain7.MoveWindow(&rtExplain7); | |
609 | + | |
610 | + CRect rtExplain8 = rtExplain7; | |
611 | + rtExplain8.left = rtExplain7.right; | |
612 | + rtExplain8.right = rtExplain8.left + kExplainWidth * 8; | |
613 | + m_cExplain8.MoveWindow(&rtExplain8); | |
614 | + | |
615 | + CRect rtExplain9 = rtExplain6; | |
616 | + rtExplain9.top = rtExplain9.bottom + 14; | |
617 | + rtExplain9.bottom = rtExplain9.top + kExplainHeight; | |
618 | + rtExplain9.right = rtExplain9.left + kExplainWidth * 6; | |
619 | + m_cExplain9.MoveWindow(&rtExplain9); | |
620 | + | |
621 | + CRect rtExplain10 = rtExplain9; | |
622 | + rtExplain10.left = rtExplain9.right; | |
623 | + rtExplain10.right = rtExplain10.left + kExplainWidth * 5; | |
624 | + m_cExplain10.MoveWindow(&rtExplain10); | |
625 | + | |
626 | + CRect rtExplain11 = rtExplain10; | |
627 | + rtExplain11.left = rtExplain10.right; | |
628 | + rtExplain11.right = rtExplain11.left + kExplainWidth * 10; | |
629 | + m_cExplain11.MoveWindow(&rtExplain11); | |
630 | + | |
631 | + CRect rtStaticCardNum; | |
632 | + rtStaticCardNum.top = rtExplain11.bottom + 24 + 30; | |
633 | + rtStaticCardNum.bottom = rtStaticCardNum.top + 36; | |
634 | + rtStaticCardNum.left = kLeftStage; | |
635 | + rtStaticCardNum.right = rtStaticCardNum.left + kExplainWidth * 4; | |
636 | + m_cStaticCardNum.MoveWindow(rtStaticCardNum); | |
637 | + | |
638 | + CRect rtEditCardNum = rtStaticCardNum; | |
639 | + rtEditCardNum.left = rtEditCardNum.right + kExplainWidth * 2; | |
640 | + rtEditCardNum.right = rtEditCardNum.left + 230; | |
641 | + m_cStaticCardNumText.MoveWindow(&rtEditCardNum); | |
642 | + | |
643 | + CRect rtUpdateButton = rtEditCardNum; | |
644 | + rtUpdateButton.left = rtUpdateButton.right + 24; | |
645 | + rtUpdateButton.right = rtUpdateButton.left + 130; | |
646 | + m_cUpdateButton.MoveWindow(&rtUpdateButton); | |
647 | + | |
648 | + CRect rtResult = rtStaticCardNum; | |
649 | + rtResult.top = rtResult.bottom + 60; | |
650 | + rtResult.bottom = rtResult.top + 36; | |
651 | + rtResult.right = rtResult.left + kExplainWidth * 6; | |
652 | + m_cResult.MoveWindow(&rtResult); | |
653 | + | |
654 | + CRect rtResultText = rtEditCardNum; | |
655 | + rtResultText.top = rtEditCardNum.bottom + 60; | |
656 | + rtResultText.bottom = rtResultText.top + kExplainHeight * 2; | |
657 | + rtResultText.left = rtResult.right; | |
658 | + m_cResultText.MoveWindow(&rtResultText); | |
659 | + | |
660 | + CRect rtResultText2 = rtResultText; | |
661 | + rtResultText2.top = rtResultText2.bottom + 30; | |
662 | + rtResultText2.bottom = rtResultText2.top + kExplainHeight * 2; | |
663 | + m_cResultText2.MoveWindow(&rtResultText2); | |
664 | +} | |
665 | + | |
666 | +void CDLCardToolDlg::SetCtrlText() | |
667 | +{ | |
668 | + m_cExplain.SetWindowText(L"使用说明"); | |
669 | + m_cExplain1.SetWindowText(L"将"); | |
670 | + m_cExplain2.SetWindowText(L"卡放置在读卡器上。"); | |
671 | + m_cExplain3.SetWindowText(L"点击"); | |
672 | + m_cExplain4.SetWindowText(L"卡片升级按钮,"); | |
673 | + m_cExplain5.SetWindowText(L"查看升级结果。"); | |
674 | + m_cExplain6.SetWindowText(L"1)若提示“"); | |
675 | + m_cExplain7.SetWindowText(L"升级成功!"); | |
676 | + m_cExplain8.SetWindowText(L"”,则升级完成。"); | |
677 | + m_cExplain9.SetWindowText(L"2)若提示“"); | |
678 | + m_cExplain10.SetWindowText(L"升级失败!"); | |
679 | + m_cExplain11.SetWindowText(L"”,请查看失败原因。"); | |
680 | + | |
681 | + m_cResult.SetWindowText(L"升级结果"); | |
682 | + | |
683 | + m_cStaticCardNum.SetWindowText(L"卡 片:"); | |
684 | +} | |
685 | + | |
686 | +void CDLCardToolDlg::SetCtrlFont() | |
687 | +{ | |
688 | + const CString kFontName = L"微软雅黑"; | |
689 | + const int kFontHeightBig = 140; | |
690 | + const int kFontHeightSmall = 120; | |
691 | + | |
692 | + m_cFontBig.CreatePointFont(kFontHeightBig, kFontName); | |
693 | + m_cFontSmall.CreatePointFont(kFontHeightSmall, kFontName); | |
694 | + | |
695 | + m_cExplain.SetFont(&m_cFontBig, FALSE); | |
696 | + m_cExplain1.SetFont(&m_cFontBig, FALSE); | |
697 | + m_cExplain2.SetFont(&m_cFontBig, FALSE); | |
698 | + m_cExplain3.SetFont(&m_cFontBig, FALSE); | |
699 | + m_cExplain4.SetFont(&m_cFontBig, FALSE); | |
700 | + m_cExplain5.SetFont(&m_cFontBig, FALSE); | |
701 | + | |
702 | + m_cExplain6.SetFont(&m_cFontSmall, FALSE); | |
703 | + m_cExplain7.SetFont(&m_cFontSmall, FALSE); | |
704 | + m_cExplain8.SetFont(&m_cFontSmall, FALSE); | |
705 | + m_cExplain9.SetFont(&m_cFontSmall, FALSE); | |
706 | + m_cExplain10.SetFont(&m_cFontSmall, FALSE); | |
707 | + m_cExplain11.SetFont(&m_cFontSmall, FALSE); | |
708 | + | |
709 | + | |
710 | + m_cStaticCardNum.SetFont(&m_cFontSmall, FALSE); | |
711 | + m_cUpdateButton.SetFont(&m_cFontSmall, FALSE); | |
712 | + m_cStaticCardNumText.SetFont(&m_cFontSmall, FALSE); | |
713 | + | |
714 | + m_cResult.SetFont(&m_cFontSmall, FALSE); | |
715 | + m_cResultText.SetFont(&m_cFontSmall, FALSE); | |
716 | + m_cResultText2.SetFont(&m_cFontSmall, FALSE); | |
717 | + | |
718 | + m_cPen.CreatePen(PS_DASH, 1, RGB(102, 102, 102)); | |
719 | +} | |
720 | + | |
721 | +void CDLCardToolDlg::SetCtrlImg() | |
722 | +{ | |
723 | + namespace fs = boost::filesystem; | |
724 | + const std::wstring sError(L"files.png"); | |
725 | + fs::path curr_exec_path = fs::current_path(); | |
726 | + curr_exec_path += L"\\res\\"; | |
727 | + std::wstring sErrorPath = curr_exec_path.wstring() + sError; | |
728 | + if (!fs::exists(sErrorPath)) | |
729 | + return; | |
730 | + HRESULT hr = m_cImg.Load(sErrorPath.c_str()); | |
731 | + m_cStaticImg.ModifyStyle(0xF, SS_BITMAP | SS_CENTERIMAGE); | |
732 | + m_cStaticImg.SetBitmap(HBITMAP(m_cImg)); | |
733 | +} | |
734 | + | |
735 | +void CDLCardToolDlg::UpdataBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) | |
736 | +{ | |
737 | + CDC* dc = CDC::FromHandle(lpDrawItemStruct->hDC); | |
738 | + UINT state = lpDrawItemStruct->itemState;; | |
739 | + CRect btn_rect, text_rc, offset_text_rect; | |
740 | + btn_rect.CopyRect(&lpDrawItemStruct->rcItem); | |
741 | + | |
742 | + const int kOffset = 1; | |
743 | + text_rc = btn_rect; | |
744 | + text_rc.OffsetRect(-kOffset, -kOffset); | |
745 | + offset_text_rect = text_rc; | |
746 | + offset_text_rect.OffsetRect(kOffset, kOffset); | |
747 | + | |
748 | + // Retrieve the button's caption | |
749 | + CString caption_str; | |
750 | + GetWindowText(caption_str); | |
751 | + | |
752 | + //TODO: read from config file. | |
753 | + const COLORREF kBtnRectEnable(RGB(17, 139, 222)), kBtnRectSelected(RGB(17, 139, 222)); | |
754 | + const COLORREF kBtnTextEnable(RGB(255, 255, 255)), kBtnTextSelected(RGB(255, 255, 255)); | |
755 | + | |
756 | + | |
757 | + if (state & ODS_SELECTED) | |
758 | + { | |
759 | + DrawFilledRect(dc, btn_rect, kBtnRectSelected); | |
760 | + DrawButtonText(dc, offset_text_rect, caption_str, kBtnTextSelected); | |
761 | + } | |
762 | + else | |
763 | + { | |
764 | + DrawFilledRect(dc, btn_rect, kBtnRectEnable); | |
765 | + DrawButtonText(dc, text_rc, caption_str, kBtnTextEnable); | |
766 | + } | |
767 | +} | |
768 | + | |
769 | +void CDLCardToolDlg::UpdataBtn::DrawFilledRect(CDC* dc, CRect rc, COLORREF color) | |
770 | +{ | |
771 | + CBrush solid_br; | |
772 | + | |
773 | + solid_br.CreateSolidBrush(color); | |
774 | + dc->FillRect(rc, &solid_br); | |
775 | +} | |
776 | + | |
777 | +void CDLCardToolDlg::UpdataBtn::DrawButtonText(CDC* dc, CRect rc, CString caption, COLORREF textcolor) | |
778 | +{ | |
779 | + const CSize text_size = dc->GetOutputTextExtent(caption); | |
780 | + const int kVerticalModifiedValue = 1; | |
781 | + const int kVerticalStartPos = (rc.Height() - text_size.cy) / 2 - kVerticalModifiedValue; | |
782 | + const uint32_t kDrawStyles = DT_CENTER | DT_VCENTER | DT_SINGLELINE; | |
783 | + | |
784 | + dc->SetTextColor(textcolor); | |
785 | + dc->SetBkMode(TRANSPARENT); | |
786 | + | |
787 | + const int kHorizontalModifiedValue = 3; | |
788 | + CRect text_rect = rc; | |
789 | + text_rect.DeflateRect(kHorizontalModifiedValue, 0, kHorizontalModifiedValue, 0); | |
790 | + text_rect.top = kVerticalStartPos; | |
791 | + text_rect.bottom = kVerticalStartPos + text_size.cy; | |
792 | + | |
793 | + dc->DrawText(caption, caption.GetLength(), text_rect, kDrawStyles); | |
794 | +} | |
795 | + | |
796 | + | |
797 | +void CDLCardToolDlg::SetResultTest(CString sTitle, CString sText) | |
798 | +{ | |
799 | + if (sTitle.Compare(kSuccessText) == 0 || sTitle.Compare(kFailedText) == 0) | |
800 | + { | |
801 | + m_bSetRed = true; | |
802 | + } | |
803 | + | |
804 | + m_cResultText.SetWindowText(sTitle); | |
805 | + m_cResultText2.SetWindowText(sText); | |
806 | +} | |
0 | 807 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLCardToolDlg.h
0 → 100644
1 | + | |
2 | +// DLCardToolDlg.h : 头文件 | |
3 | +// | |
4 | + | |
5 | +#pragma once | |
6 | +#include "afxwin.h" | |
7 | +#include "afxcmn.h" | |
8 | +#include "password_machine.h" | |
9 | +#include "DLConfig.h" | |
10 | + | |
11 | +enum LOG_TYPE | |
12 | +{ | |
13 | + LOG_TRACE = 0, | |
14 | + LOG_ERROR | |
15 | +}; | |
16 | + | |
17 | +enum KEY_TYPE | |
18 | +{ | |
19 | + KT_DCCK = 0, | |
20 | + KT_DEAK, | |
21 | + KT_DAMK, | |
22 | + KT_DACK, | |
23 | +}; | |
24 | + | |
25 | + | |
26 | +enum ENCRYPT_TYPE | |
27 | +{ | |
28 | + ET_PWM = 0, //加密机加密 | |
29 | + ET_DES, //软加密 | |
30 | + ET_NO, //未加密 | |
31 | + ET_UNKNOWN //未知加密状态 | |
32 | +}; | |
33 | + | |
34 | +typedef struct CARD_STATE_INFO | |
35 | +{ | |
36 | + bool bAlreadyUpdate; | |
37 | + | |
38 | + CARD_STATE_INFO() | |
39 | + { | |
40 | + bAlreadyUpdate = false; | |
41 | + } | |
42 | + | |
43 | + CARD_STATE_INFO& operator= (const CARD_STATE_INFO stuSD) | |
44 | + { | |
45 | + this->bAlreadyUpdate = stuSD.bAlreadyUpdate; | |
46 | + return *this; | |
47 | + } | |
48 | +}CardStateInfo; | |
49 | + | |
50 | +typedef struct CARD_BASIC_INFO | |
51 | +{ | |
52 | + std::string sCardNum; | |
53 | + std::string sCardOldSn; //沈阳老卡写在05文件中的sn号 | |
54 | + | |
55 | + CARD_BASIC_INFO& operator= (const CARD_BASIC_INFO stuSD) | |
56 | + { | |
57 | + this->sCardNum = stuSD.sCardNum; | |
58 | + this->sCardOldSn = stuSD.sCardOldSn; | |
59 | + return *this; | |
60 | + } | |
61 | + | |
62 | +}BasicInfo; | |
63 | + | |
64 | +// CDLCardToolDlg 对话框 | |
65 | +class CDLCardToolDlg : public CDialogEx | |
66 | +{ | |
67 | + | |
68 | + class UpdataBtn : public CButton | |
69 | + { | |
70 | + private: | |
71 | + virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); | |
72 | + void DrawFilledRect(CDC* dc, CRect rc, COLORREF color); | |
73 | + void DrawButtonText(CDC* dc, CRect rc, CString caption, COLORREF textcolor); | |
74 | + }; | |
75 | + | |
76 | +// 构造 | |
77 | +public: | |
78 | + CDLCardToolDlg(CWnd* pParent = NULL); // 标准构造函数 | |
79 | + | |
80 | +// 对话框数据 | |
81 | + enum { IDD = IDD_DLCARDTOOL_DIALOG }; | |
82 | + | |
83 | + protected: | |
84 | + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 | |
85 | + | |
86 | + | |
87 | +// 实现 | |
88 | +protected: | |
89 | + HICON m_hIcon; | |
90 | + | |
91 | + // 生成的消息映射函数 | |
92 | + virtual BOOL OnInitDialog(); | |
93 | + afx_msg void OnPaint(); | |
94 | + afx_msg HCURSOR OnQueryDragIcon(); | |
95 | + DECLARE_MESSAGE_MAP() | |
96 | + | |
97 | +private: | |
98 | + void SetMsgLog(CString sText, LOG_TYPE emLogType = LOG_TRACE, int iErrorCode = 0); | |
99 | + CardStateInfo CheckCardState(BasicInfo biCardInfo); | |
100 | + CardStateInfo ReadJson(CString sResponseBody); | |
101 | + void GetMainKey(bool bUsePWM, std::string sSN, std::string &sDCCK); | |
102 | + BasicInfo ReadBasicInfo(); | |
103 | + std::string CalculateKey(BasicInfo biCardBasicInfo, KEY_TYPE ktKeyType, int iEncryptType); | |
104 | + void InstallKey(std::string sDir, std::string sNewKey, std::string sMainKey, KEY_TYPE ktKeyType, int iKeyID); | |
105 | + void WriteData(std::string sDir, int iFileID, int iOffest, int iLen, std::string sKey, std::string sData); | |
106 | + | |
107 | + void ResizeCtrl(); | |
108 | + void SetCtrlText(); | |
109 | + void SetCtrlFont(); | |
110 | + void SetCtrlImg(); | |
111 | + | |
112 | + void SetResultTest(CString sTitle, CString sText); | |
113 | + | |
114 | +public: | |
115 | + afx_msg void OnBnClickedButtonCardupdate(); | |
116 | + | |
117 | +private: | |
118 | + CStatic m_cExplain; | |
119 | + CStatic m_cExplain1; | |
120 | + CStatic m_cExplain2; | |
121 | + CStatic m_cExplain3; | |
122 | + CStatic m_cExplain4; | |
123 | + CStatic m_cExplain5; | |
124 | + CStatic m_cExplain6; | |
125 | + CStatic m_cExplain7; | |
126 | + CStatic m_cExplain8; | |
127 | + CStatic m_cExplain9; | |
128 | + CStatic m_cExplain10; | |
129 | + CStatic m_cExplain11; | |
130 | + UpdataBtn m_cUpdateButton; | |
131 | + | |
132 | + CStatic m_cResult; | |
133 | + CStatic m_cResultText; | |
134 | + CStatic m_cResultText2; | |
135 | + | |
136 | + CStatic m_cStaticImg; | |
137 | + | |
138 | + PWDMachine m_cPWDMachine; | |
139 | + CDLConfig m_cConfig; | |
140 | +private: | |
141 | + CStatic m_cStaticCardNum; | |
142 | + CStatic m_cStaticCardNumText; | |
143 | + | |
144 | + CFont m_cFontBig; | |
145 | + CFont m_cFontSmall; | |
146 | + | |
147 | + CImage m_cImg; | |
148 | + | |
149 | + CPen m_cPen; | |
150 | +public: | |
151 | + afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); | |
152 | + | |
153 | +private: | |
154 | + bool m_bSetRed; | |
155 | +}; | ... | ... |
card_file_tool/DLCardTool/DLConfig.cpp
0 → 100644
1 | + | |
2 | +#include "stdafx.h" | |
3 | +#include "DLConfig.h" | |
4 | + | |
5 | +#include <sstream> | |
6 | + | |
7 | +#include "mangerCmd.h" | |
8 | +#include "commonCmd.h" | |
9 | +#include "afxinet.h" | |
10 | +#include <string> | |
11 | +#include <cstdint> | |
12 | +#include "tinyxml.h" | |
13 | + | |
14 | + | |
15 | +CDLConfig::CDLConfig(): | |
16 | +m_u16Port(0), m_u32PWMPort(0), m_bUsePWM(false) | |
17 | +{ | |
18 | +} | |
19 | + | |
20 | +CDLConfig::~CDLConfig() | |
21 | +{} | |
22 | + | |
23 | +bool CDLConfig::ReadConfig() | |
24 | +{ | |
25 | + bool bResult = false; | |
26 | + | |
27 | + CString sXMLPath = L".\\Config\\PWMConfig.xml"; | |
28 | + | |
29 | + TiXmlDocument xmlDoc(wstr_2_str(sXMLPath.GetBuffer()).c_str()); | |
30 | + if (xmlDoc.LoadFile()) | |
31 | + { | |
32 | + try | |
33 | + { | |
34 | + bResult = true; | |
35 | + TiXmlElement *pRootEle = xmlDoc.RootElement(); | |
36 | + TiXmlElement *pPWMIP = pRootEle->FirstChildElement(); | |
37 | + m_sPWMIP = pPWMIP->GetText(); | |
38 | + TiXmlElement *pPWMPort = pPWMIP->NextSiblingElement(); | |
39 | + std::string sPWMPort = pPWMPort->GetText(); | |
40 | + m_u32PWMPort = atoi(sPWMPort.c_str()); | |
41 | + TiXmlElement *pHost = pPWMPort->NextSiblingElement(); | |
42 | + m_sHost = pHost->GetText(); | |
43 | + TiXmlElement *pPort = pHost->NextSiblingElement(); | |
44 | + std::string sPort = pPort->GetText(); | |
45 | + m_u16Port = atoi(sPort.c_str()); | |
46 | + TiXmlElement *pUsePWM = pPort->NextSiblingElement(); | |
47 | + std::string sUsePWM = pUsePWM->GetText(); | |
48 | + m_bUsePWM = sUsePWM.compare("0") == 0 ? false : true; | |
49 | + } | |
50 | + catch (...) | |
51 | + { | |
52 | + bResult = false; | |
53 | + } | |
54 | + } | |
55 | + | |
56 | + return bResult; | |
57 | +} | |
58 | + | |
59 | +CString CDLConfig::GetModulePath() | |
60 | +{ | |
61 | + CString sPath; | |
62 | + | |
63 | + TCHAR szPath[MAX_PATH]; | |
64 | + GetModuleFileName(NULL, szPath, MAX_PATH); | |
65 | + CString sMudolePath = szPath; | |
66 | + CString sMudoleName = AfxGetAppName(); | |
67 | + sPath = sMudolePath.Left(sMudolePath.GetLength() - sMudoleName.GetLength() - 4); | |
68 | + return sPath; | |
69 | +} | |
0 | 70 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLConfig.h
0 → 100644
1 | +#ifndef DL_CONFIG_H | |
2 | +#define DL_CONFIG_H | |
3 | + | |
4 | +#include "stdafx.h" | |
5 | + | |
6 | +class CDLConfig | |
7 | +{ | |
8 | +public: | |
9 | + CDLConfig(); | |
10 | + ~CDLConfig(); | |
11 | + | |
12 | + bool ReadConfig(); | |
13 | +private: | |
14 | + CString GetModulePath(); | |
15 | + | |
16 | +public: | |
17 | + std::string m_sPWMIP; | |
18 | + uint32_t m_u32PWMPort; | |
19 | + std::string m_sHost; | |
20 | + uint16_t m_u16Port; | |
21 | + bool m_bUsePWM; | |
22 | +}; | |
23 | + | |
24 | +#endif | |
0 | 25 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLDes.h
0 → 100644
1 | +#ifndef DL_DES_H | |
2 | +#define DL_DES_H | |
3 | + | |
4 | +#define DL_DLL_API extern "C" __declspec(dllexport) | |
5 | + | |
6 | +DL_DLL_API void DES(unsigned char *key, unsigned char *s_test, unsigned char *d_text); | |
7 | +DL_DLL_API void _DES(unsigned char *key, unsigned char *s_test, unsigned char *d_text); | |
8 | + | |
9 | +#endif | |
0 | 10 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLLogo.ico
0 → 100644
No preview for this file type
card_file_tool/DLCardTool/DLTools.cpp
0 → 100644
1 | +#include "stdafx.h" | |
2 | +#include "DLTools.h" | |
3 | +#include <locale> | |
4 | + | |
5 | + | |
6 | +void Log(CString sLog) | |
7 | +{ | |
8 | + CStdioFile fileLog; | |
9 | + CString sPath; | |
10 | + TCHAR szPath[MAX_PATH]; | |
11 | + GetModuleFileName(NULL, szPath, MAX_PATH); | |
12 | + CString sMudolePath = szPath; | |
13 | + CString sMudoleName = AfxGetAppName(); | |
14 | + sPath = sMudolePath.Left(sMudolePath.GetLength() - sMudoleName.GetLength() - 4); | |
15 | + | |
16 | + if (_access(sPath + "Log", 0) == -1) | |
17 | + { | |
18 | + _mkdir(sPath + "Log"); | |
19 | + } | |
20 | + | |
21 | + CFileStatus statusFile; | |
22 | + statusFile.m_size = 0; | |
23 | + CString sLogPath = sPath + "Log\\DLCardTool.log"; | |
24 | + CFile::GetStatus(sLogPath, statusFile); | |
25 | + | |
26 | + CTime tmCurTime; | |
27 | + tmCurTime = CTime::GetCurrentTime(); | |
28 | + CString sData = tmCurTime.Format("%y%m%d-%H%M%S"); | |
29 | + | |
30 | + setlocale(LC_CTYPE, ("chs")); | |
31 | + | |
32 | + CString sText = sData + L" " + sLog; | |
33 | + if (statusFile.m_size > 1024 * 1024 * 10) | |
34 | + { | |
35 | + if (fileLog.Open(sLogPath, CFile::modeCreate | CFile::modeWrite)) | |
36 | + { | |
37 | + fileLog.WriteString(sText); | |
38 | + fileLog.WriteString(L"\n"); | |
39 | + fileLog.Close(); | |
40 | + } | |
41 | + } | |
42 | + else | |
43 | + { | |
44 | + if (fileLog.Open(sLogPath, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) | |
45 | + { | |
46 | + fileLog.SeekToEnd(); | |
47 | + fileLog.WriteString(sText); | |
48 | + fileLog.WriteString(L"\n"); | |
49 | + fileLog.Close(); | |
50 | + } | |
51 | + } | |
52 | +} | |
53 | + | |
54 | +int Encrypt(unsigned char* pSrc, unsigned char u8Len, unsigned char* pKey, unsigned char* pCiphertText) | |
55 | +{ | |
56 | + int iResult = 0; | |
57 | + | |
58 | + uint8_t au8DataBlock[50][8] = { 0 }; | |
59 | + | |
60 | + int iBlockCount = 0, iCoverPos = 0, iBlockNum = 0; | |
61 | + iBlockCount = u8Len / 8; | |
62 | + iCoverPos = u8Len % 8; | |
63 | + | |
64 | + while (iBlockCount > 0) | |
65 | + { | |
66 | + memcpy(au8DataBlock[iBlockNum], pSrc, 8); | |
67 | + pSrc += 8; | |
68 | + --iBlockCount; | |
69 | + ++iBlockNum; | |
70 | + } | |
71 | + | |
72 | + if (iCoverPos) | |
73 | + { | |
74 | + memcpy(au8DataBlock[iBlockNum], pSrc, iCoverPos); | |
75 | + au8DataBlock[iBlockNum][iCoverPos] = 0x80; | |
76 | + ++iCoverPos; | |
77 | + for (int index = iCoverPos; iCoverPos < 8; ++iCoverPos) | |
78 | + { | |
79 | + au8DataBlock[iBlockNum][iCoverPos] = 0x00; | |
80 | + } | |
81 | + } | |
82 | + else | |
83 | + { | |
84 | + --iBlockNum; | |
85 | + } | |
86 | + | |
87 | + uint8_t au8KeyL[8] = { 0 }, au8KeyR[8] = { 0 }; | |
88 | + memcpy(au8KeyL, pKey, 8); | |
89 | + memcpy(au8KeyR, pKey, 8); | |
90 | + for (int index = 0; index <= iBlockNum; ++index) | |
91 | + { | |
92 | + uint8_t au8Cipher1[8] = { 0 }, au8Cipher2[8] = { 0 }; | |
93 | + DES(au8KeyL, au8DataBlock[index], au8Cipher1); | |
94 | + _DES(au8KeyR, au8Cipher1, au8Cipher2); | |
95 | + DES(au8KeyL, au8Cipher2, &pCiphertText[index * 8]); | |
96 | + } | |
97 | + | |
98 | + return iResult; | |
99 | +} | |
100 | + | |
101 | +bool HexToChar(unsigned char* pHex, int iHexLen, unsigned char* pChar) | |
102 | +{ | |
103 | + bool bResult = true; | |
104 | + if (pHex && iHexLen && pChar) | |
105 | + { | |
106 | + int iCharCount = 0; | |
107 | + for (int index = 0; index < iHexLen; ++index) | |
108 | + { | |
109 | + char cNum[3] = { 0 }; | |
110 | + if (pHex[index] <= 0x0f) | |
111 | + { | |
112 | + pChar[iCharCount] = '0'; | |
113 | + ++iCharCount; | |
114 | + sprintf_s(cNum, "%X", pHex[index]); | |
115 | + pChar[iCharCount] = cNum[0]; | |
116 | + ++iCharCount; | |
117 | + } | |
118 | + else | |
119 | + { | |
120 | + sprintf_s(cNum, "%2X", pHex[index]); | |
121 | + pChar[iCharCount] = cNum[0]; | |
122 | + ++iCharCount; | |
123 | + pChar[iCharCount] = cNum[1]; | |
124 | + ++iCharCount; | |
125 | + } | |
126 | + } | |
127 | + } | |
128 | + return bResult; | |
129 | +} | |
130 | + | |
131 | +bool CharToHex(unsigned char* pStr, unsigned char& cHex) | |
132 | +{ | |
133 | + bool bResult = true; | |
134 | + | |
135 | + unsigned char aHex[2] = { 0 }, cTemp = 0; | |
136 | + if (pStr) | |
137 | + { | |
138 | + int iCount = 2; | |
139 | + do | |
140 | + { | |
141 | + char cStr = tolower(pStr[iCount - 1]); | |
142 | + switch (cStr) | |
143 | + { | |
144 | + case '0': | |
145 | + case '1': | |
146 | + case '2': | |
147 | + case '3': | |
148 | + case '4': | |
149 | + case '5': | |
150 | + case '6': | |
151 | + case '7': | |
152 | + case '8': | |
153 | + case '9': | |
154 | + { | |
155 | + cTemp = atoi(&cStr); | |
156 | + break; | |
157 | + } | |
158 | + case 'a': | |
159 | + { | |
160 | + cTemp = 10; | |
161 | + break; | |
162 | + } | |
163 | + case 'b': | |
164 | + { | |
165 | + cTemp = 11; | |
166 | + break; | |
167 | + } | |
168 | + case 'c': | |
169 | + { | |
170 | + cTemp = 12; | |
171 | + break; | |
172 | + } | |
173 | + case 'd': | |
174 | + { | |
175 | + cTemp = 13; | |
176 | + break; | |
177 | + } | |
178 | + case 'e': | |
179 | + { | |
180 | + cTemp = 14; | |
181 | + break; | |
182 | + } | |
183 | + case 'f': | |
184 | + { | |
185 | + cTemp = 15; | |
186 | + break; | |
187 | + } | |
188 | + } | |
189 | + aHex[iCount - 1] = cTemp; | |
190 | + --iCount; | |
191 | + } while (iCount); | |
192 | + | |
193 | + cHex = (aHex[0] << 4) + aHex[1]; | |
194 | + } | |
195 | + else | |
196 | + { | |
197 | + bResult = false; | |
198 | + } | |
199 | + return bResult; | |
200 | +} | |
201 | + | |
202 | +bool StringToHex(unsigned char* pStr, int iLen, unsigned char* pHex) | |
203 | +{ | |
204 | + bool bResult = true; | |
205 | + | |
206 | + int iStrIndex = 0; | |
207 | + int index = 0; | |
208 | + while (bResult && iStrIndex < iLen) | |
209 | + { | |
210 | + bResult = CharToHex(&pStr[iStrIndex], pHex[index]); | |
211 | + ++index; | |
212 | + iStrIndex += 2; | |
213 | + } | |
214 | + | |
215 | + if (!bResult) | |
216 | + { | |
217 | + throw std::exception("9999"); | |
218 | + } | |
219 | + /*for (int index = 0, iStrIndex = 0; iStrIndex < iLen; ++index, iStrIndex += 2) | |
220 | + { | |
221 | + CharToHex(&pStr[iStrIndex], pHex[index]); | |
222 | + }*/ | |
223 | + | |
224 | + return bResult; | |
225 | +} | |
0 | 226 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/DLTools.h
0 → 100644
1 | +#pragma once | |
2 | +#ifndef DL_TOOLS | |
3 | +#define DL_TOOLS | |
4 | + | |
5 | +#include "stdafx.h" | |
6 | +#include <cstring> | |
7 | + | |
8 | +void Log(CString sLog); | |
9 | + | |
10 | +//extern void StrCopy(char* pDes, char* pSrc, int iLen); | |
11 | + | |
12 | +int Encrypt(unsigned char* pSrc, unsigned char u8Len, unsigned char* pKey, unsigned char* pCiphertText); | |
13 | +bool HexToChar(unsigned char* pHex, int iHexLen, unsigned char* pChar); | |
14 | +bool CharToHex(unsigned char* pStr, unsigned char& cHex); | |
15 | +bool StringToHex(unsigned char* pStr, int iLen, unsigned char* pHex); | |
16 | + | |
17 | +#endif | |
0 | 18 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/ReadMe.txt
0 → 100644
1 | +================================================================================ | |
2 | + MICROSOFT 基础类库 : DLCardTool 项目概述 | |
3 | +=============================================================================== | |
4 | + | |
5 | +应用程序向导已为您创建了此 DLCardTool 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法,还可作为您编写应用程序的起点。 | |
6 | + | |
7 | +本文件概要介绍组成 DLCardTool 应用程序的每个文件的内容。 | |
8 | + | |
9 | +DLCardTool.vcxproj | |
10 | + 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 | |
11 | + | |
12 | +DLCardTool.vcxproj.filters | |
13 | + 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 | |
14 | + | |
15 | +DLCardTool.h | |
16 | + 这是应用程序的主头文件。 | |
17 | + 其中包括其他项目特定的标头(包括 Resource.h),并声明 CDLCardToolApp 应用程序类。 | |
18 | + | |
19 | +DLCardTool.cpp | |
20 | + 这是包含应用程序类 CDLCardToolApp 的主应用程序源文件。 | |
21 | + | |
22 | +DLCardTool.rc | |
23 | + 这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。项目资源包含在 2052 中。 | |
24 | + | |
25 | +res\DLCardTool.ico | |
26 | + 这是用作应用程序图标的图标文件。此图标包括在主资源文件 DLCardTool.rc 中。 | |
27 | + | |
28 | +res\DLCardTool.rc2 | |
29 | + 此文件包含不在 Microsoft Visual C++ 中进行编辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。 | |
30 | + | |
31 | + | |
32 | +///////////////////////////////////////////////////////////////////////////// | |
33 | + | |
34 | +应用程序向导创建一个对话框类: | |
35 | + | |
36 | +DLCardToolDlg.h、DLCardToolDlg.cpp - 对话框 | |
37 | + 这些文件包含 CDLCardToolDlg 类。此类定义应用程序的主对话框的行为。对话框模板包含在 DLCardTool.rc 中,该文件可以在 Microsoft Visual C++ 中编辑。 | |
38 | + | |
39 | +///////////////////////////////////////////////////////////////////////////// | |
40 | + | |
41 | +其他功能: | |
42 | + | |
43 | +ActiveX 控件 | |
44 | + 该应用程序包含对使用 ActiveX 控件的支持。 | |
45 | + | |
46 | +///////////////////////////////////////////////////////////////////////////// | |
47 | + | |
48 | +其他标准文件: | |
49 | + | |
50 | +StdAfx.h, StdAfx.cpp | |
51 | + 这些文件用于生成名为 DLCardTool.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 | |
52 | + | |
53 | +Resource.h | |
54 | + 这是标准头文件,可用于定义新的资源 ID。Microsoft Visual C++ 将读取并更新此文件。 | |
55 | + | |
56 | +DLCardTool.manifest | |
57 | + Windows XP 使用应用程序清单文件来描述特定版本的并行程序集的应用程序依赖项。加载程序使用这些信息来从程序集缓存中加载相应的程序集,并保护其不被应用程序访问。应用程序清单可能会包含在内,以作为与应用程序可执行文件安装在同一文件夹中的外部 .manifest 文件进行重新分发,它还可能以资源的形式包含在可执行文件中。 | |
58 | +///////////////////////////////////////////////////////////////////////////// | |
59 | + | |
60 | +其他注释: | |
61 | + | |
62 | +应用程序向导使用“TODO:”来指示应添加或自定义的源代码部分。 | |
63 | + | |
64 | +如果应用程序使用共享 DLL 中的 MFC,您将需要重新分发 MFC DLL。如果应用程序所使用的语言与操作系统的区域设置不同,则还需要重新分发相应的本地化资源 mfc110XXX.DLL。 | |
65 | +有关上述话题的更多信息,请参见 MSDN 文档中有关重新分发 Visual C++ 应用程序的部分。 | |
66 | + | |
67 | +///////////////////////////////////////////////////////////////////////////// | ... | ... |
card_file_tool/DLCardTool/commonCmd.h
0 → 100644
1 | +/* | |
2 | + * Copyright (c) 2011, 广州江南科友union | |
3 | + * All rights reserved. | |
4 | + * 文件名称: commonCmd.h | |
5 | + * 摘 要: 应用加密机通用指令接口的定义 | |
6 | + * 当前版本: 1.0, 编写者: 杨武,修改时间: 2011-11-22 修改内容: 创建 | |
7 | + * | |
8 | + */ | |
9 | +extern "C" | |
10 | +{ | |
11 | + | |
12 | + // 装载打印格式 0062 | |
13 | + //输入参数:hsmIp 加密机IP地址 | |
14 | + //输入参数:hsmPort 加密机对外服务端口 | |
15 | + //输入参数:timeout socket超时等待时间 ms单位 | |
16 | + //输入参数:isCfg 0:不从配置文件读取lenOfMsg、hsmIp、hsmPort、timeOut、hsmLenOfMsgHeader、isLenOfHsmMsg 启用输入参数中的这些信息 1:从配置文件中读取上述信息 | |
17 | + //输入参数:clientSocket -1:采用的是短连接方式,需要在函数体完成socket的创建和释放 >0:采用长连接方式,复用该套接字句柄 | |
18 | + //输入参数:hsmLenOfMsgHeader 消息头长度 | |
19 | + //输入参数:isLenOfHsmMsg 报文长度(两字节) | |
20 | + //输入参数:typeOfFormat 格式类型 P:打印PIN格式 K:打印密钥成分格式 | |
21 | + //输入参数:lenOfFormat 格式长度 小于512 | |
22 | + //输入参数:formatInfo 格式内容 | |
23 | + //返回值: <0:失败;=0成功 | |
24 | + _declspec(dllexport) int union_syj1001_storePrintFormat(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char typeOfFormat,int lenOfFormat,char * formatInfo); | |
25 | + //用指定密钥对指定数据进行加密 A050 | |
26 | + //输入参数:typeOfAlgo 算法类型 | |
27 | + //输入参数:indexOfKey 加密密钥索引 | |
28 | + //输入参数:keyValByMK 加密密钥值 | |
29 | + //输入参数:iniVec 初始向量 | |
30 | + //输入参数:lenOfSData 数据块长度 | |
31 | + //输入参数:SData 数据块 | |
32 | + //输出参数:DData 加密后数据块 | |
33 | + //返回值: <0:失败;>0成功 返回数据长度 | |
34 | + _declspec(dllexport) int union_syj1001_enctyptData(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char * typeOfAlgo,char* indexOfKey,char *keyValByMK,char*iniVec,int lenOfSData,char *SData,char* DData); | |
35 | + //用指定密钥对指定数据进行加密 S050 | |
36 | + //输入参数:typeOfAlgo 算法类型 | |
37 | + //输入参数:indexOfKey 加密密钥索引 | |
38 | + //输入参数:keyValByMK 加密密钥值 | |
39 | + //输入参数:iniVec 初始向量 | |
40 | + //输入参数:lenOfSData 数据块长度 | |
41 | + //输入参数:SData 数据块 | |
42 | + //输出参数:DData 加密后数据块 | |
43 | + //返回值: <0:失败;>0成功 返回数据长度 | |
44 | + _declspec(dllexport) int union_syj1001_enctyptData_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char * typeOfAlgo,char* indexOfKey,char *keyValByMK,char*iniVec,int lenOfSData,char *SData,char* DData); | |
45 | + //用指定密钥对指定数据进行解密 A050 | |
46 | + //输入参数:typeOfAlgo 算法类型 | |
47 | + //输入参数:indexOfKey 解密密钥索引 | |
48 | + //输入参数:keyValByMK 解密密钥值 | |
49 | + //输入参数:iniVec 初始向量 | |
50 | + //输入参数:lenOfSData 数据块长度 | |
51 | + //输入参数:SData 数据块 | |
52 | + //输出参数:DData 解密后数据块 | |
53 | + //返回值: <0:失败;>0成功 返回数据长度 | |
54 | + _declspec(dllexport) int union_syj1001_dectyptData(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char * typeOfAlgo,char* indexOfKey,char *keyValByMK,char*iniVec,int lenOfSData,char *SData,char* DData); | |
55 | + //用指定密钥对指定数据进行解密 S050 | |
56 | + //输入参数:typeOfAlgo 算法类型 | |
57 | + //输入参数:indexOfKey 解密密钥索引 | |
58 | + //输入参数:keyValByMK 解密密钥值 | |
59 | + //输入参数:iniVec 初始向量 | |
60 | + //输入参数:lenOfSData 数据块长度 | |
61 | + //输入参数:SData 数据块 | |
62 | + //输出参数:DData 解密后数据块 | |
63 | + //返回值: <0:失败;>0成功 返回数据长度 | |
64 | + _declspec(dllexport) int union_syj1001_dectyptData_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char * typeOfAlgo,char* indexOfKey,char *keyValByMK,char*iniVec,int lenOfSData,char *SData,char* DData); | |
65 | + //对指定数据生成MAC 0030 | |
66 | + //输入参数:typeOfAlgo 算法类型 | |
67 | + //输入参数:indexOfKey 密钥索引 | |
68 | + //输入参数:keyValByMK 密钥值 | |
69 | + //输入参数:iniVec 初始向量 | |
70 | + //输入参数:lenOfMacData macData数据长度 | |
71 | + //输入参数:macData | |
72 | + //输出参数:mac | |
73 | + //返回值: <0:失败;>0成功返回的mac数据长度 | |
74 | + _declspec(dllexport) int union_syj1001_genMac(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char *typeOfAlgo,char * indexOfKey,char*keyValByMK,char*iniVec,int lenOfMacData,char*macData,char*mac); | |
75 | + //对指定数据生成MAC S030 | |
76 | + //输入参数:typeOfAlgo 算法类型 | |
77 | + //输入参数:indexOfKey 密钥索引 | |
78 | + //输入参数:keyValByMK 密钥值 | |
79 | + //输入参数:iniVec 初始向量 | |
80 | + //输入参数:lenOfMacData macData数据长度 | |
81 | + //输入参数:macData | |
82 | + //输出参数:mac | |
83 | + //返回值: <0:失败;>0成功返回的mac数据长度 | |
84 | + _declspec(dllexport) int union_syj1001_genMac_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char *typeOfAlgo,char * indexOfKey,char*keyValByMK,char*iniVec,int lenOfMacData,char*macData,char*mac); | |
85 | + //对指定数据验证MAC 0032 | |
86 | + //输入参数:typeOfAlgo 算法类型 | |
87 | + //输入参数:indexOfKey 密钥索引 | |
88 | + //输入参数:keyValByMK 密钥值 | |
89 | + //输入参数:iniVec 初始向量 | |
90 | + //输入参数:lenOfMac mac长度 MAC值中需要进行验证的字节数;最小值为4,最大值16 | |
91 | + //输入参数:mac | |
92 | + //输入参数:lenOfMacData macData数据长度 | |
93 | + //输入参数:macData | |
94 | + //返回值: <0:失败;=0成功 | |
95 | + _declspec(dllexport) int union_syj1001_verifyMac(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*typeOfAlgo,char*indexOfKey,char*keyValByMK,char*iniVec,int lenOfMac,char*mac,int lenOfMacData,char *macData); | |
96 | + //对指定数据验证MAC S032 | |
97 | + //输入参数:typeOfAlgo 算法类型 | |
98 | + //输入参数:indexOfKey 密钥索引 | |
99 | + //输入参数:keyValByMK 密钥值 | |
100 | + //输入参数:iniVec 初始向量 | |
101 | + //输入参数:lenOfMac mac长度 MAC值中需要进行验证的字节数;最小值为4,最大值16 | |
102 | + //输入参数:mac | |
103 | + //输入参数:lenOfMacData macData数据长度 | |
104 | + //输入参数:macData | |
105 | + //返回值: <0:失败;=0成功 | |
106 | + _declspec(dllexport) int union_syj1001_verifyMac_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*typeOfAlgo,char*indexOfKey,char*keyValByMK,char*iniVec,int lenOfMac,char*mac,int lenOfMacData,char *macData); | |
107 | + //用指定密钥对明文PIN进行加密 0020 | |
108 | + //输入参数:indexOfKey 密钥索引 | |
109 | + //输入参数:keyValByMK 密钥值 | |
110 | + //输入参数:formatOfPinBlock PIN块的格式 | |
111 | + //输入参数:clearPin PIN块的明文 | |
112 | + //输入参数:accNo 账号 | |
113 | + //输出参数:pinByKEK pin密文 | |
114 | + //返回值: <0:失败;>0成功 输出数据长度 | |
115 | + _declspec(dllexport) int union_syj1001_enctyptPin(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*indexOfKey,char*keyValByMK,char*formatOfPinBlock, char*clearPin,char*accNo,char*pinByKEK); | |
116 | + //用指定密钥对明文PIN进行加密 S020 | |
117 | + //输入参数:indexOfKey 密钥索引 | |
118 | + //输入参数:keyValByMK 密钥值 | |
119 | + //输入参数:formatOfPinBlock PIN块的格式 | |
120 | + //输入参数:clearPin PIN块的明文 | |
121 | + //输入参数:accNo 账号 | |
122 | + //输出参数:pinByKEK pin密文 | |
123 | + //返回值: <0:失败;>0成功 输出数据长度 | |
124 | + _declspec(dllexport) int union_syj1001_enctyptPin_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*indexOfKey,char*keyValByMK,char*formatOfPinBlock, char*clearPin,char*accNo,char*pinByKEK); | |
125 | + //用指定密钥对密文PIN进行解密 0024 | |
126 | + //输入参数:indexOfKey 密钥索引 | |
127 | + //输入参数:keyValByMK 密钥值 | |
128 | + //输入参数:formatOfPinBlock PIN块的格式 | |
129 | + //输入参数:pinByKEK pin密文 | |
130 | + //输入参数:accNo 账号 | |
131 | + //输出参数:clearPin PIN块的明文 | |
132 | + //返回值: <0:失败;=0成功 | |
133 | + _declspec(dllexport) int union_syj1001_dectyptPin(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*indexOfKey,char*keyValByMK,char*formatOfPinBlock, char*pinByKEK,char*accNo,char*clearPin); | |
134 | + //用指定密钥对密文PIN进行解密 S024 | |
135 | + //输入参数:indexOfKey 密钥索引 | |
136 | + //输入参数:keyValByMK 密钥值 | |
137 | + //输入参数:formatOfPinBlock PIN块的格式 | |
138 | + //输入参数:pinByKEK pin密文 | |
139 | + //输入参数:accNo 账号 | |
140 | + //输出参数:clearPin PIN块的明文 | |
141 | + //返回值: <0:失败;=0成功 | |
142 | + _declspec(dllexport) int union_syj1001_dectyptPin_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*indexOfKey,char*keyValByMK,char*formatOfPinBlock, char*pinByKEK,char*accNo,char*clearPin); | |
143 | + //打印PIN/PIN请求数据 00PE | |
144 | + //输入参数:typeOfFile 文档类型 | |
145 | + //输入参数:indexOfKey 密钥索引 | |
146 | + //输入参数:keyValByMK 密钥值 | |
147 | + //输入参数:accNo 账号 | |
148 | + //输入参数:pinBlock pin密文 | |
149 | + //输入参数:formatOfPinBlock PIN块的格式 | |
150 | + //输入参数:printFieldNo 在打印格域个数,最多16个 | |
151 | + //输入参数:... 在打印格式定义中作为“Print Field s”定义的打印域 | |
152 | + //返回值: <0:失败;=0成功 | |
153 | + _declspec(dllexport) int union_syj1001_printPin(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char typeOfFile,char* indexOfKey,char*keyValByMK,char*accNo,char*pinBlock,char*formatOfPinBlock,int printFieldNo,...); | |
154 | + //打印PIN/PIN请求数据 S0PE | |
155 | + //输入参数:typeOfFile 文档类型 | |
156 | + //输入参数:indexOfKey 密钥索引 | |
157 | + //输入参数:keyValByMK 密钥值 | |
158 | + //输入参数:accNo 账号 | |
159 | + //输入参数:pinBlock pin密文 | |
160 | + //输入参数:formatOfPinBlock PIN块的格式 | |
161 | + //输入参数:printFieldNo 在打印格域个数,最多16个 | |
162 | + //输入参数:... 在打印格式定义中作为“Print Field s”定义的打印域 | |
163 | + //返回值: <0:失败;=0成功 | |
164 | + _declspec(dllexport) int union_syj1001_printPin_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char typeOfFile,char* indexOfKey,char*keyValByMK,char*accNo,char*pinBlock,char*formatOfPinBlock,int printFieldNo,...); | |
165 | + //用指定密钥对离散数据衍生密钥 0064 | |
166 | + //输入参数:indexOfRKey 根密钥索引 | |
167 | + //输入参数:rKeyValByMK 根密钥值 | |
168 | + //输入参数:disperseCount 离散次数 | |
169 | + //输出参数:newKeyVal MK加密下的过程密钥/子密钥密文 | |
170 | + //输出参数:chkVal 过程密钥/子密钥的校验值 | |
171 | + //输入参数:... 离散数据 | |
172 | + //返回值: <0:失败;>0成功 密钥长度 | |
173 | + _declspec(dllexport) int union_syj1001_disperseKey(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*indexOfRKey,char* rKeyValByMK,char*newKeyVal,char*chkVal,int disperseCount,...); | |
174 | + //用指定密钥对离散数据衍生密钥 S064 | |
175 | + //输入参数:indexOfRKey 根密钥索引 | |
176 | + //输入参数:rKeyValByMK 根密钥值 | |
177 | + //输入参数:disperseCount 离散次数 | |
178 | + //输出参数:newKeyVal MK加密下的过程密钥/子密钥密文 | |
179 | + //输出参数:chkVal 过程密钥/子密钥的校验值 | |
180 | + //输入参数:... 离散数据 | |
181 | + //返回值: <0:失败;>0成功 密钥长度 | |
182 | + _declspec(dllexport) int union_syj1001_disperseKey_SM1(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char*indexOfRKey,char* rKeyValByMK,char*newKeyVal,char*chkVal,int disperseCount,...); | |
183 | +}; | |
0 | 184 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/files.png
0 → 100644
1002 Bytes
card_file_tool/DLCardTool/json_parser.hpp
0 → 100644
1 | +// ---------------------------------------------------------------------------- | |
2 | +// Copyright (C) 2002-2006 Marcin Kalicinski | |
3 | +// | |
4 | +// Distributed under the Boost Software License, Version 1.0. | |
5 | +// (See accompanying file LICENSE_1_0.txt or copy at | |
6 | +// http://www.boost.org/LICENSE_1_0.txt) | |
7 | +// | |
8 | +// For more information, see www.boost.org | |
9 | +// ---------------------------------------------------------------------------- | |
10 | +#ifndef BOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED | |
11 | +#define BOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED | |
12 | + | |
13 | +#include <boost/property_tree/ptree.hpp> | |
14 | +#include <boost/property_tree/detail/json_parser_read.hpp> | |
15 | + | |
16 | +//@PATCH!!! Patched by the "iCardClient" developing team. | |
17 | +//#include <boost/property_tree/detail/json_parser_write.hpp> // Do not include the original version. | |
18 | +#include "json_parser_write.hpp" // Include our patch version instead. | |
19 | +//@} | |
20 | + | |
21 | +#include <boost/property_tree/detail/json_parser_error.hpp> | |
22 | + | |
23 | +#include <fstream> | |
24 | +#include <string> | |
25 | +#include <locale> | |
26 | + | |
27 | +namespace boost { namespace property_tree { namespace json_parser | |
28 | +{ | |
29 | + | |
30 | + /** | |
31 | + * Read JSON from a the given stream and translate it to a property tree. | |
32 | + * @note Clears existing contents of property tree. In case of error the | |
33 | + * property tree unmodified. | |
34 | + * @note Items of JSON arrays are translated into ptree keys with empty | |
35 | + * names. Members of objects are translated into named keys. | |
36 | + * @note JSON data can be a string, a numeric value, or one of literals | |
37 | + * "null", "true" and "false". During parse, any of the above is | |
38 | + * copied verbatim into ptree data string. | |
39 | + * @throw json_parser_error In case of error deserializing the property | |
40 | + * tree. | |
41 | + * @param stream Stream from which to read in the property tree. | |
42 | + * @param[out] pt The property tree to populate. | |
43 | + */ | |
44 | + template<class Ptree> | |
45 | + void read_json(std::basic_istream< | |
46 | + typename Ptree::key_type::value_type | |
47 | + > &stream, | |
48 | + Ptree &pt) | |
49 | + { | |
50 | + read_json_internal(stream, pt, std::string()); | |
51 | + } | |
52 | + | |
53 | + /** | |
54 | + * Read JSON from a the given file and translate it to a property tree. | |
55 | + * @note Clears existing contents of property tree. In case of error the | |
56 | + * property tree unmodified. | |
57 | + * @note Items of JSON arrays are translated into ptree keys with empty | |
58 | + * names. Members of objects are translated into named keys. | |
59 | + * @note JSON data can be a string, a numeric value, or one of literals | |
60 | + * "null", "true" and "false". During parse, any of the above is | |
61 | + * copied verbatim into ptree data string. | |
62 | + * @throw json_parser_error In case of error deserializing the property | |
63 | + * tree. | |
64 | + * @param filename Name of file from which to read in the property tree. | |
65 | + * @param[out] pt The property tree to populate. | |
66 | + * @param loc The locale to use when reading in the file contents. | |
67 | + */ | |
68 | + template<class Ptree> | |
69 | + void read_json(const std::string &filename, | |
70 | + Ptree &pt, | |
71 | + const std::locale &loc = std::locale()) | |
72 | + { | |
73 | + std::basic_ifstream<typename Ptree::key_type::value_type> | |
74 | + stream(filename.c_str()); | |
75 | + if (!stream) | |
76 | + BOOST_PROPERTY_TREE_THROW(json_parser_error( | |
77 | + "cannot open file", filename, 0)); | |
78 | + stream.imbue(loc); | |
79 | + read_json_internal(stream, pt, filename); | |
80 | + } | |
81 | + | |
82 | + /** | |
83 | + * Translates the property tree to JSON and writes it the given output | |
84 | + * stream. | |
85 | + * @note Any property tree key containing only unnamed subkeys will be | |
86 | + * rendered as JSON arrays. | |
87 | + * @pre @e pt cannot contain keys that have both subkeys and non-empty data. | |
88 | + * @throw json_parser_error In case of error translating the property tree | |
89 | + * to JSON or writing to the output stream. | |
90 | + * @param stream The stream to which to write the JSON representation of the | |
91 | + * property tree. | |
92 | + * @param pt The property tree to tranlsate to JSON and output. | |
93 | + * @param pretty Whether to pretty-print. Defaults to true for backward | |
94 | + * compatibility. | |
95 | + */ | |
96 | + template<class Ptree> | |
97 | + void write_json(std::basic_ostream< | |
98 | + typename Ptree::key_type::value_type | |
99 | + > &stream, | |
100 | + const Ptree &pt, | |
101 | + bool pretty = true) | |
102 | + { | |
103 | + write_json_internal(stream, pt, std::string(), pretty); | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * Translates the property tree to JSON and writes it the given file. | |
108 | + * @note Any property tree key containing only unnamed subkeys will be | |
109 | + * rendered as JSON arrays. | |
110 | + * @pre @e pt cannot contain keys that have both subkeys and non-empty data. | |
111 | + * @throw json_parser_error In case of error translating the property tree | |
112 | + * to JSON or writing to the file. | |
113 | + * @param filename The name of the file to which to write the JSON | |
114 | + * representation of the property tree. | |
115 | + * @param pt The property tree to translate to JSON and output. | |
116 | + * @param loc The locale to use when writing out to the output file. | |
117 | + * @param pretty Whether to pretty-print. Defaults to true and last place | |
118 | + * for backward compatibility. | |
119 | + */ | |
120 | + template<class Ptree> | |
121 | + void write_json(const std::string &filename, | |
122 | + const Ptree &pt, | |
123 | + const std::locale &loc = std::locale(), | |
124 | + bool pretty = true) | |
125 | + { | |
126 | + std::basic_ofstream<typename Ptree::key_type::value_type> | |
127 | + stream(filename.c_str()); | |
128 | + if (!stream) | |
129 | + BOOST_PROPERTY_TREE_THROW(json_parser_error( | |
130 | + "cannot open file", filename, 0)); | |
131 | + stream.imbue(loc); | |
132 | + write_json_internal(stream, pt, filename, pretty); | |
133 | + } | |
134 | + | |
135 | +} } } | |
136 | + | |
137 | +namespace boost { namespace property_tree | |
138 | +{ | |
139 | + using json_parser::read_json; | |
140 | + using json_parser::write_json; | |
141 | + using json_parser::json_parser_error; | |
142 | +} } | |
143 | + | |
144 | +#endif | ... | ... |
card_file_tool/DLCardTool/json_parser_write.hpp
0 → 100644
1 | +// ---------------------------------------------------------------------------- | |
2 | +// Copyright (C) 2002-2006 Marcin Kalicinski | |
3 | +// | |
4 | +// Distributed under the Boost Software License, Version 1.0. | |
5 | +// (See accompanying file LICENSE_1_0.txt or copy at | |
6 | +// http://www.boost.org/LICENSE_1_0.txt) | |
7 | +// | |
8 | +// For more information, see www.boost.org | |
9 | +// ---------------------------------------------------------------------------- | |
10 | +#ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_WRITE_HPP_INCLUDED | |
11 | +#define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_WRITE_HPP_INCLUDED | |
12 | + | |
13 | +#include <boost/property_tree/ptree.hpp> | |
14 | +#include <boost/next_prior.hpp> | |
15 | +#include <boost/type_traits/make_unsigned.hpp> | |
16 | +#include <string> | |
17 | +#include <ostream> | |
18 | +#include <iomanip> | |
19 | + | |
20 | +namespace boost { namespace property_tree { namespace json_parser | |
21 | +{ | |
22 | + | |
23 | + // Create necessary escape sequences from illegal characters | |
24 | + template<class Ch> | |
25 | + std::basic_string<Ch> create_escapes(const std::basic_string<Ch> &s) | |
26 | + { | |
27 | + std::basic_string<Ch> result; | |
28 | + typename std::basic_string<Ch>::const_iterator b = s.begin(); | |
29 | + typename std::basic_string<Ch>::const_iterator e = s.end(); | |
30 | + while (b != e) | |
31 | + { | |
32 | + // This assumes an ASCII superset. But so does everything in PTree. | |
33 | + // We escape everything outside ASCII, because this code can't | |
34 | + // handle high unicode characters. | |
35 | + if (*b == 0x20 || *b == 0x21 || (*b >= 0x23 && *b <= 0x2E) || | |
36 | + (*b >= 0x30 && *b <= 0x5B) || (*b >= 0x5D && *b <= 0xFF) || | |
37 | + (*b >= -0x80 && *b < 0)) // PATCH!!! Patched by the "iCardClient" developing team, this will pass UTF-8 signed chars. | |
38 | + result += *b; | |
39 | + else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b'); | |
40 | + else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f'); | |
41 | + else if (*b == Ch('\n')) result += Ch('\\'), result += Ch('n'); | |
42 | + else if (*b == Ch('\r')) result += Ch('\\'), result += Ch('r'); | |
43 | + else if (*b == Ch('\t')) result += Ch('\\'), result += Ch('t'); | |
44 | + else if (*b == Ch('/')) result += Ch('\\'), result += Ch('/'); | |
45 | + else if (*b == Ch('"')) result += Ch('\\'), result += Ch('"'); | |
46 | + else if (*b == Ch('\\')) result += Ch('\\'), result += Ch('\\'); | |
47 | + else | |
48 | + { | |
49 | + const char *hexdigits = "0123456789ABCDEF"; | |
50 | + typedef typename make_unsigned<Ch>::type UCh; | |
51 | + unsigned long u = (std::min)(static_cast<unsigned long>( | |
52 | + static_cast<UCh>(*b)), | |
53 | + 0xFFFFul); | |
54 | + int d1 = u / 4096; u -= d1 * 4096; | |
55 | + int d2 = u / 256; u -= d2 * 256; | |
56 | + int d3 = u / 16; u -= d3 * 16; | |
57 | + int d4 = u; | |
58 | + result += Ch('\\'); result += Ch('u'); | |
59 | + result += Ch(hexdigits[d1]); result += Ch(hexdigits[d2]); | |
60 | + result += Ch(hexdigits[d3]); result += Ch(hexdigits[d4]); | |
61 | + result += *b; | |
62 | + } | |
63 | + ++b; | |
64 | + } | |
65 | + return result; | |
66 | + } | |
67 | + | |
68 | + template<class Ptree> | |
69 | + void write_json_helper(std::basic_ostream<typename Ptree::key_type::value_type> &stream, | |
70 | + const Ptree &pt, | |
71 | + int indent, bool pretty) | |
72 | + { | |
73 | + | |
74 | + typedef typename Ptree::key_type::value_type Ch; | |
75 | + typedef typename std::basic_string<Ch> Str; | |
76 | + | |
77 | + // Value or object or array | |
78 | + if (indent > 0 && pt.empty()) | |
79 | + { | |
80 | + // Write value | |
81 | + Str data = create_escapes(pt.template get_value<Str>()); | |
82 | + stream << Ch('"') << data << Ch('"'); | |
83 | + | |
84 | + } | |
85 | + else if (indent > 0 && pt.count(Str()) == pt.size()) | |
86 | + { | |
87 | + // Write array | |
88 | + stream << Ch('['); | |
89 | + if (pretty) stream << Ch('\n'); | |
90 | + typename Ptree::const_iterator it = pt.begin(); | |
91 | + for (; it != pt.end(); ++it) | |
92 | + { | |
93 | + if (pretty) stream << Str(4 * (indent + 1), Ch(' ')); | |
94 | + write_json_helper(stream, it->second, indent + 1, pretty); | |
95 | + if (boost::next(it) != pt.end()) | |
96 | + stream << Ch(','); | |
97 | + if (pretty) stream << Ch('\n'); | |
98 | + } | |
99 | + if (pretty) stream << Str(4 * indent, Ch(' ')); | |
100 | + stream << Ch(']'); | |
101 | + | |
102 | + } | |
103 | + else | |
104 | + { | |
105 | + // Write object | |
106 | + stream << Ch('{'); | |
107 | + if (pretty) stream << Ch('\n'); | |
108 | + typename Ptree::const_iterator it = pt.begin(); | |
109 | + for (; it != pt.end(); ++it) | |
110 | + { | |
111 | + if (pretty) stream << Str(4 * (indent + 1), Ch(' ')); | |
112 | + stream << Ch('"') << create_escapes(it->first) << Ch('"') << Ch(':'); | |
113 | + if (pretty) stream << Ch(' '); | |
114 | + write_json_helper(stream, it->second, indent + 1, pretty); | |
115 | + if (boost::next(it) != pt.end()) | |
116 | + stream << Ch(','); | |
117 | + if (pretty) stream << Ch('\n'); | |
118 | + } | |
119 | + if (pretty) stream << Str(4 * indent, Ch(' ')); | |
120 | + stream << Ch('}'); | |
121 | + } | |
122 | + | |
123 | + } | |
124 | + | |
125 | + // Verify if ptree does not contain information that cannot be written to json | |
126 | + template<class Ptree> | |
127 | + bool verify_json(const Ptree &pt, int depth) | |
128 | + { | |
129 | + | |
130 | + typedef typename Ptree::key_type::value_type Ch; | |
131 | + typedef typename std::basic_string<Ch> Str; | |
132 | + | |
133 | + // Root ptree cannot have data | |
134 | + if (depth == 0 && !pt.template get_value<Str>().empty()) | |
135 | + return false; | |
136 | + | |
137 | + // Ptree cannot have both children and data | |
138 | + if (!pt.template get_value<Str>().empty() && !pt.empty()) | |
139 | + return false; | |
140 | + | |
141 | + // Check children | |
142 | + typename Ptree::const_iterator it = pt.begin(); | |
143 | + for (; it != pt.end(); ++it) | |
144 | + if (!verify_json(it->second, depth + 1)) | |
145 | + return false; | |
146 | + | |
147 | + // Success | |
148 | + return true; | |
149 | + | |
150 | + } | |
151 | + | |
152 | + // Write ptree to json stream | |
153 | + template<class Ptree> | |
154 | + void write_json_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, | |
155 | + const Ptree &pt, | |
156 | + const std::string &filename, | |
157 | + bool pretty) | |
158 | + { | |
159 | + if (!verify_json(pt, 0)) | |
160 | + BOOST_PROPERTY_TREE_THROW(json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0)); | |
161 | + write_json_helper(stream, pt, 0, pretty); | |
162 | + stream << std::endl; | |
163 | + if (!stream.good()) | |
164 | + BOOST_PROPERTY_TREE_THROW(json_parser_error("write error", filename, 0)); | |
165 | + } | |
166 | + | |
167 | +} } } | |
168 | + | |
169 | +#endif | ... | ... |
card_file_tool/DLCardTool/mangerCmd.h
0 → 100644
1 | +/* | |
2 | + * Copyright (c) 2011, 广州江南科友union | |
3 | + * All rights reserved. | |
4 | + * 文件名称: mangerCmd.h | |
5 | + * 摘 要: 应用加密机和密钥管理指令接口的定义 | |
6 | + * 当前版本: 1.0, 编写者: 杨武,修改时间: 2011-11-22 修改内容: 创建 | |
7 | + * | |
8 | + */ | |
9 | +extern "C" | |
10 | +{ | |
11 | + //和应用加密机创建socket连接 | |
12 | + //输入参数:hsmIp 加密机IP地址 | |
13 | + //输入参数:hsmPort 加密机对外服务端口 | |
14 | + //输入参数:isCfg 0:不从配置文件读取hsmIp、hsmPort启用输入参数中的这些信息 1:从配置文件中读取上述信息 | |
15 | + //返回值: <0:失败;>0 成功,所创建的套接字句柄 | |
16 | + _declspec(dllexport) int union_syj1001_connect(char * hsmIp,int hsmPort,int isCfg); | |
17 | + //断开和应用加密机的socket连接 | |
18 | + //输入参数:clientSocket socket套接字句柄 | |
19 | + //返回值: <0:失败;0:成功 | |
20 | + _declspec(dllexport) int union_syj1001_disConnect(int clientSocket); | |
21 | + //透传接口,将组好的报文转发给应用加密机 | |
22 | + //输入参数:msg 报文 | |
23 | + //输入参数:hsmIp 加密机IP地址 | |
24 | + //输入参数:hsmPort 加密机对外服务端口 | |
25 | + //输入参数:timeOut socket超时等待时间 ms单位 | |
26 | + //输入参数:isCfg 0:不从配置文件读取lenOfMsg、hsmIp、hsmPort、timeOut、hsmLenOfMsgHeader、isLenOfHsmMsg 启用输入参数中的这些信息 1:从配置文件中读取上述信息 | |
27 | + //输入参数:clientSocket -1:采用的是短连接方式,需要在函数体完成socket的创建和释放 >0:采用长连接方式,复用该套接字句柄 | |
28 | + //输入参数:hsmLenOfMsgHeader 消息头长度 | |
29 | + //输入参数:isLenOfHsmMsg 报文长度(两字节) | |
30 | + //输出参数:revMsg 返回的报文相应 | |
31 | + //返回值: <0:失败;>0:输出的报文长度 | |
32 | + _declspec(dllexport) int union_syj1001_direct_sendMsg(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket,char* msg, char *revMsg); | |
33 | + //获取加密机基本信息 命令码 0000 | |
34 | + //输入参数:hsmIp 加密机IP地址 | |
35 | + //输入参数:hsmPort 加密机对外服务端口 | |
36 | + //输入参数:timeOut socket超时等待时间 ms单位 | |
37 | + //输入参数:isCfg 0:不从配置文件读取lenOfMsg、hsmIp、hsmPort、timeOut、hsmLenOfMsgHeader、isLenOfHsmMsg 启用输入参数中的这些信息 1:从配置文件中读取上述信息 | |
38 | + //输入参数:clientSocket -1:采用的是短连接方式,需要在函数体完成socket的创建和释放 >0:采用长连接方式,复用该套接字句柄 | |
39 | + //输入参数:hsmLenOfMsgHeader 消息头长度 | |
40 | + //输入参数:isLenOfHsmMsg 报文长度(两字节) | |
41 | + //输出参数:revMsg 返回的报文相应 | |
42 | + //返回值: <0:失败;=0:revMsg中包含主密钥校验值,和加密机基本信息;=13 加密机基本信息 | |
43 | + _declspec(dllexport) int union_syj1001_getHsmBaseInfo(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket, char *revMsg); | |
44 | + //给加密机授权 命令码 0002 | |
45 | + //输入参数:hsmIp 加密机IP地址 | |
46 | + //输入参数:hsmPort 加密机对外服务端口 | |
47 | + //输入参数:timeOut socket超时等待时间 ms单位 | |
48 | + //输入参数:isCfg 0:不从配置文件读取lenOfMsg、hsmIp、hsmPort、timeOut、hsmLenOfMsgHeader、isLenOfHsmMsg 启用输入参数中的这些信息 1:从配置文件中读取上述信息 | |
49 | + //输入参数:clientSocket -1:采用的是短连接方式,需要在函数体完成socket的创建和释放 >0:采用长连接方式,复用该套接字句柄 | |
50 | + //输入参数:hsmLenOfMsgHeader 消息头长度 | |
51 | + //输入参数:isLenOfHsmMsg 报文长度(两字节) | |
52 | + //返回值: <0:失败;=0成功 | |
53 | + _declspec(dllexport) int union_syj1001_setAuthApply(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket); | |
54 | + //取消加密机授权 命令码 0004 | |
55 | + //输入参数:hsmIp 加密机IP地址 | |
56 | + //输入参数:hsmPort 加密机对外服务端口 | |
57 | + //输入参数:timeOut socket超时等待时间 ms单位 | |
58 | + //输入参数:isCfg 0:不从配置文件读取lenOfMsg、hsmIp、hsmPort、timeOut、hsmLenOfMsgHeader、isLenOfHsmMsg 启用输入参数中的这些信息 1:从配置文件中读取上述信息 | |
59 | + //输入参数:clientSocket -1:采用的是短连接方式,需要在函数体完成socket的创建和释放 >0:采用长连接方式,复用该套接字句柄 | |
60 | + //输入参数:hsmLenOfMsgHeader 消息头长度 | |
61 | + //输入参数:isLenOfHsmMsg 报文长度(两字节) | |
62 | + //返回值: <0:失败;=0成功 | |
63 | + _declspec(dllexport) int union_syj1001_cancelAuthApply(char* hsmIp,int hsmPort,int timeout,int isCfg,int hsmLenOfMsgHeader,int isLenOfHsmMsg,int clientSocket); | |
64 | + | |
65 | +}; | ... | ... |
card_file_tool/DLCardTool/openssl_aes_cbc.cpp
0 → 100644
1 | + | |
2 | +#include "stdafx.h" | |
3 | + | |
4 | + | |
5 | + | |
6 | +#include <fstream> | |
7 | +#include <exception> | |
8 | +#include <array> | |
9 | +#include <random> | |
10 | +#include <climits> | |
11 | +#include <chrono> | |
12 | + | |
13 | +#include <windows.h> | |
14 | + | |
15 | +namespace | |
16 | +{ | |
17 | + const int kBlockSize = 16; | |
18 | + const int kKeyLength = 16;// 128Bit | |
19 | + const std::array<unsigned char, kKeyLength> kUserKey{ { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'i' } }; | |
20 | + const std::array<unsigned char, kKeyLength> kDCCK{ { '4', '3', '4', '3', '4', 'b', 'f', 'f', '4', '3', '4', '3', '4', 'b', 'f', 'f' } }; | |
21 | + const std::array<unsigned char, kKeyLength> kDACK{ { '4', '1', '4', '3', '4', 'b', 'f', 'f', '4', '1', '4', '3', '4', 'b', 'f', 'f' } }; | |
22 | + const std::array<unsigned char, kKeyLength> kDEAK{ { '4', '5', '4', '1', '4', 'b', 'f', 'f', '4', '5', '4', '1', '4', 'b', 'f', 'f' } }; | |
23 | + const std::array<unsigned char, kKeyLength> kDAMK{ { '4', '1', '4', 'd', '4', 'b', '3', '1', '4', '1', '4', 'd', '4', 'b', '3', '1' } }; | |
24 | + | |
25 | + class AesCbcInterface | |
26 | + { | |
27 | + typedef struct AesKeySt | |
28 | + { | |
29 | + unsigned int rd_key[60]; | |
30 | + int rounds; | |
31 | + }AES_KEY; | |
32 | + | |
33 | + enum CryptType | |
34 | + { | |
35 | + AesDecrypt = 0, | |
36 | + AesEncrypt = 1 | |
37 | + }; | |
38 | + | |
39 | + typedef int(__cdecl *AesSetEncryptKey)(const unsigned char *userKey, const int bits, AES_KEY *key); | |
40 | + typedef int(__cdecl *AesSetDecryptKey)(const unsigned char *userKey, const int bits, AES_KEY *key); | |
41 | + typedef void(__cdecl *AesCbcEncrypt)(const unsigned char *in, unsigned char *out, | |
42 | + size_t length, const AES_KEY *key, unsigned char *ivec, const int enc); | |
43 | + | |
44 | + public: | |
45 | + AesCbcInterface(const std::array<unsigned char, kKeyLength>& user_key, const std::array<unsigned char, kKeyLength>& dcck, | |
46 | + const std::array<unsigned char, kKeyLength>& dack, const std::array<unsigned char, kKeyLength>& deak, | |
47 | + const std::array<unsigned char, kKeyLength>& damk) | |
48 | + : m_user_key(user_key), m_dcck_key(dcck), m_dack_key(dack), m_deak_key(deak), m_damk_key(damk) | |
49 | + { | |
50 | + Init(); | |
51 | + } | |
52 | + | |
53 | + const std::string Encrypt(const std::string& plaintext, int iKeyIndex = 0) const | |
54 | + { | |
55 | + unsigned char c_plaintext[kBlockSize]; | |
56 | + unsigned char c_ciphertext[kBlockSize]; | |
57 | + unsigned char iv[kBlockSize]; | |
58 | + | |
59 | + std::default_random_engine generator((unsigned int)std::chrono::system_clock::now().time_since_epoch().count()); | |
60 | + std::uniform_int_distribution<int> distribution(0, UCHAR_MAX);// Make generates number in the range of unsigned char value space. | |
61 | + for (int index = 0; index < kBlockSize; ++index) | |
62 | + iv[index] = distribution(generator); | |
63 | + | |
64 | + unsigned int kKeyBits = m_user_key.size() * 8; | |
65 | + AES_KEY aes_key; | |
66 | + switch (iKeyIndex) | |
67 | + { | |
68 | + case 0: | |
69 | + { | |
70 | + m_fn_aes_set_encrypt_key(m_user_key.data(), kKeyBits, &aes_key); | |
71 | + break; | |
72 | + } | |
73 | + case 1: | |
74 | + { | |
75 | + m_fn_aes_set_encrypt_key(m_dcck_key.data(), kKeyBits, &aes_key); | |
76 | + break; | |
77 | + } | |
78 | + case 2: | |
79 | + { | |
80 | + m_fn_aes_set_encrypt_key(m_dack_key.data(), kKeyBits, &aes_key); | |
81 | + break; | |
82 | + } | |
83 | + case 3: | |
84 | + { | |
85 | + m_fn_aes_set_encrypt_key(m_deak_key.data(), kKeyBits, &aes_key); | |
86 | + break; | |
87 | + } | |
88 | + case 4: | |
89 | + { | |
90 | + m_fn_aes_set_encrypt_key(m_damk_key.data(), kKeyBits, &aes_key); | |
91 | + break; | |
92 | + } | |
93 | + } | |
94 | + | |
95 | + std::string ciphertext; | |
96 | + ciphertext.append((char*)iv, kBlockSize);// 保存iv数据 | |
97 | + | |
98 | + // 对明文长度加密保存 | |
99 | + const int kPlaintextLength = plaintext.length(); | |
100 | + std::string ciphertext_length = std::to_string(kPlaintextLength); | |
101 | + memset(c_ciphertext, '\0', kBlockSize); | |
102 | + memset(c_plaintext, '\0', kBlockSize); | |
103 | + memcpy(c_plaintext, ciphertext_length.c_str(), ciphertext_length.length()); | |
104 | + m_fn_aes_cbc_encrypt(c_plaintext, c_ciphertext, kBlockSize, &aes_key, iv, AesEncrypt); | |
105 | + ciphertext.append((char*)c_ciphertext, kBlockSize); | |
106 | + memcpy(iv, c_ciphertext, kBlockSize);// 同时,密文做iv数据,以备下次加密 | |
107 | + | |
108 | + int index = 0; | |
109 | + for (; index + kBlockSize < kPlaintextLength; index += kBlockSize) | |
110 | + {// 按块取出明文,做加密处理 | |
111 | + memset(c_ciphertext, '\0', kBlockSize);// 密文空间清零 | |
112 | + memcpy(c_plaintext, plaintext.c_str() + index, kBlockSize);//取出明文 | |
113 | + m_fn_aes_cbc_encrypt(c_plaintext, c_ciphertext, kBlockSize, &aes_key, iv, AesEncrypt); // 加密,iv数据发生变化 | |
114 | + ciphertext.append((char*)c_ciphertext, kBlockSize); //保存密文 | |
115 | + memcpy(iv, c_ciphertext, kBlockSize);// 同时,密文做iv数据,以备下次加密 | |
116 | + } | |
117 | + | |
118 | + // 数据没有按块对齐时,尾部未对齐数据做加密 | |
119 | + if (kPlaintextLength - index > 0) | |
120 | + { | |
121 | + memset(c_ciphertext, '\0', kBlockSize); | |
122 | + memset(c_plaintext, '\0', kBlockSize); | |
123 | + memcpy(c_plaintext, plaintext.c_str() + index, kPlaintextLength - index); | |
124 | + m_fn_aes_cbc_encrypt(c_plaintext, c_ciphertext, kBlockSize, &aes_key, iv, AesEncrypt); | |
125 | + ciphertext.append((char*)c_ciphertext, kBlockSize); | |
126 | + } | |
127 | + | |
128 | + return ciphertext; | |
129 | + } | |
130 | + | |
131 | + const std::string Decrypt(const std::string& ciphertext, int iKeyIndex = 0) const | |
132 | + { | |
133 | + unsigned char c_plaintext[kBlockSize]; | |
134 | + unsigned char c_ciphertext[kBlockSize]; | |
135 | + unsigned char iv[kBlockSize]; | |
136 | + | |
137 | + const int kKeyBits = m_user_key.size() * 8; | |
138 | + AES_KEY aes_key; | |
139 | + switch (iKeyIndex) | |
140 | + { | |
141 | + case 0: | |
142 | + { | |
143 | + m_fn_aes_set_decrypt_key(m_user_key.data(), kKeyBits, &aes_key); | |
144 | + break; | |
145 | + } | |
146 | + case 1: | |
147 | + { | |
148 | + m_fn_aes_set_decrypt_key(m_dcck_key.data(), kKeyBits, &aes_key); | |
149 | + break; | |
150 | + } | |
151 | + case 2: | |
152 | + { | |
153 | + m_fn_aes_set_decrypt_key(m_dack_key.data(), kKeyBits, &aes_key); | |
154 | + break; | |
155 | + } | |
156 | + case 3: | |
157 | + { | |
158 | + m_fn_aes_set_decrypt_key(m_deak_key.data(), kKeyBits, &aes_key); | |
159 | + break; | |
160 | + } | |
161 | + case 4: | |
162 | + { | |
163 | + m_fn_aes_set_decrypt_key(m_damk_key.data(), kKeyBits, &aes_key); | |
164 | + break; | |
165 | + } | |
166 | + } | |
167 | + | |
168 | + std::string plaintext; | |
169 | + | |
170 | + const int kCiphertextLength = ciphertext.length(); | |
171 | + if (0 != kCiphertextLength % kBlockSize || kCiphertextLength < kBlockSize * 3) | |
172 | + throw std::exception("数据太少,或损坏!无法解密。");// 数据必须按块对齐且至少有3块数据【iv、长度、内容】 | |
173 | + | |
174 | + int index = 0; | |
175 | + memcpy(iv, ciphertext.c_str() + index, kBlockSize);// 读取iv数据 | |
176 | + index += kBlockSize; | |
177 | + | |
178 | + // 获取明文数据长度 | |
179 | + memset(c_plaintext, '\0', kBlockSize);// 明文空间清零 | |
180 | + memcpy(c_ciphertext, ciphertext.c_str() + index, kBlockSize);//取出密文 | |
181 | + m_fn_aes_cbc_encrypt(c_ciphertext, c_plaintext, kBlockSize, &aes_key, iv, AesDecrypt);// 解密 | |
182 | + const int kPlaintextLength = ::atoi((char*)c_plaintext); | |
183 | + memcpy(iv, c_ciphertext, kBlockSize); // 同时,密文做iv数据,以备下次加密 | |
184 | + index += kBlockSize; | |
185 | + | |
186 | + for (; index < kCiphertextLength; index += kBlockSize) | |
187 | + { | |
188 | + memset(c_plaintext, '\0', kBlockSize);// 明文空间清零 | |
189 | + memcpy(c_ciphertext, ciphertext.c_str() + index, kBlockSize);//取出密文 | |
190 | + m_fn_aes_cbc_encrypt(c_ciphertext, c_plaintext, kBlockSize, &aes_key, iv, AesDecrypt);// 解密 | |
191 | + plaintext.append((char*)c_plaintext, kBlockSize);//保存明文 | |
192 | + memcpy(iv, c_ciphertext, kBlockSize); // 同时,密文做iv数据,以备下次加密 | |
193 | + } | |
194 | + | |
195 | + if ((int)plaintext.length() > kPlaintextLength) // 去掉块补齐数据 | |
196 | + plaintext.erase(kPlaintextLength, plaintext.length() - kPlaintextLength); | |
197 | + | |
198 | + return plaintext; | |
199 | + } | |
200 | + | |
201 | + private: | |
202 | + void Init() | |
203 | + { | |
204 | + const CString kDLLFile = L"./libeay32.dll"; | |
205 | + m_dll_handle = LoadLibrary(kDLLFile); | |
206 | + | |
207 | + if (NULL != m_dll_handle) | |
208 | + { | |
209 | + m_fn_aes_set_encrypt_key = (AesSetEncryptKey)GetProcAddress(m_dll_handle, "AES_set_encrypt_key"); | |
210 | + m_fn_aes_set_decrypt_key = (AesSetDecryptKey)GetProcAddress(m_dll_handle, "AES_set_decrypt_key"); | |
211 | + m_fn_aes_cbc_encrypt = (AesCbcEncrypt)GetProcAddress(m_dll_handle, "AES_cbc_encrypt"); | |
212 | + } | |
213 | + else | |
214 | + throw std::exception(("Fail to load the OpenSSL-AEC-BCB DLL from path : " + wstr_2_str(kDLLFile)).c_str()); | |
215 | + } | |
216 | + | |
217 | + private: | |
218 | + const std::array<unsigned char, kKeyLength> m_user_key; | |
219 | + const std::array<unsigned char, kKeyLength> m_dcck_key; | |
220 | + const std::array<unsigned char, kKeyLength> m_dack_key; | |
221 | + const std::array<unsigned char, kKeyLength> m_deak_key; | |
222 | + const std::array<unsigned char, kKeyLength> m_damk_key; | |
223 | + | |
224 | + HINSTANCE m_dll_handle; | |
225 | + AesSetEncryptKey m_fn_aes_set_encrypt_key; | |
226 | + AesSetDecryptKey m_fn_aes_set_decrypt_key; | |
227 | + AesCbcEncrypt m_fn_aes_cbc_encrypt; | |
228 | + }; | |
229 | + | |
230 | + const AesCbcInterface& GetAesCbcInterface() | |
231 | + { | |
232 | + static AesCbcInterface aes_cbc_interface(kUserKey, kDCCK, kDACK, kDEAK, kDAMK); // 出错会抛出异常 | |
233 | + return aes_cbc_interface; | |
234 | + } | |
235 | +} | |
236 | + | |
237 | +namespace AES_CBC | |
238 | +{ | |
239 | + std::string Encrypt(const std::string& plaintext, int iKeyIndex) | |
240 | + { | |
241 | + return GetAesCbcInterface().Encrypt(plaintext, iKeyIndex); | |
242 | + } | |
243 | + | |
244 | + std::string Decrypt(const std::string& ciphertext, int iKeyIndex) | |
245 | + { | |
246 | + return GetAesCbcInterface().Decrypt(ciphertext, iKeyIndex); | |
247 | + } | |
248 | + | |
249 | + void EncryptToFile(const std::string& plaintext, const std::string& ciphertext_file_name) | |
250 | + { | |
251 | + std::ofstream ciphertext_file(ciphertext_file_name, std::ios_base::out | std::ios_base::binary); | |
252 | + | |
253 | + if (!ciphertext_file.is_open()) | |
254 | + throw std::exception("创建或打开密文文件失败!"); | |
255 | + | |
256 | + ciphertext_file << Encrypt(plaintext); | |
257 | + ciphertext_file.close(); | |
258 | + } | |
259 | + | |
260 | + std::string DecryptFromFile(const std::string& ciphertext_file_name) | |
261 | + { | |
262 | + std::ifstream ciphertext_file(ciphertext_file_name, std::ios_base::in | std::ios_base::binary); | |
263 | + if (!ciphertext_file.is_open()) | |
264 | + throw std::exception("打开密文文件失败,请检查!"); | |
265 | + | |
266 | + std::string ciphertext((std::istreambuf_iterator<char>(ciphertext_file)), std::istreambuf_iterator<char>()); | |
267 | + ciphertext_file.close(); | |
268 | + | |
269 | + return Decrypt(ciphertext); | |
270 | + } | |
271 | + | |
272 | + void EncryptFileToFile(const std::string& plaintext_file_name, const std::string& ciphertext_file_name) | |
273 | + { | |
274 | + std::ifstream plaintext_file(plaintext_file_name, std::ios_base::in); | |
275 | + if (!plaintext_file.is_open()) | |
276 | + throw std::exception("打开明文文件失败,请检查!"); | |
277 | + | |
278 | + std::string plaintext((std::istreambuf_iterator<char>(plaintext_file)), std::istreambuf_iterator<char>()); | |
279 | + plaintext_file.close(); | |
280 | + | |
281 | + EncryptToFile(plaintext, ciphertext_file_name); | |
282 | + } | |
283 | + | |
284 | + void DecryptFileToFile(const std::string& ciphertext_file_name, const std::string& plaintext_file_name) | |
285 | + { | |
286 | + std::ofstream plaintext_file(plaintext_file_name, std::ios_base::out); | |
287 | + if (!plaintext_file.is_open()) | |
288 | + throw std::exception("创建或打开明文文件失败!"); | |
289 | + | |
290 | + plaintext_file << DecryptFromFile(ciphertext_file_name); | |
291 | + plaintext_file.close(); | |
292 | + } | |
293 | +} // AES_CBC | |
0 | 294 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/openssl_aes_cbc.h
0 → 100644
1 | +#ifndef ETRADECLIENT_UTILITY_OPENSSL_AES_CBC_H_INCLUDED | |
2 | +#define ETRADECLIENT_UTILITY_OPENSSL_AES_CBC_H_INCLUDED | |
3 | + | |
4 | +#include <string> | |
5 | + | |
6 | +/*Notice: the APIs of "openssl_aes" may throw exceptions when error happens, these exception messages contain | |
7 | + Chinese characters which are encoding in GBK encoding, so the caller has to call "gbk_2_wstr" to convert the | |
8 | + exception message to std::wstring in Unicode encoding.*/ | |
9 | +namespace AES_CBC | |
10 | +{ | |
11 | + //iKeyIndex:0为默认加密配置文件秘钥,1为dcck秘钥,2为dack秘钥,3为deak秘钥,4为damk秘钥 | |
12 | + std::string Encrypt(const std::string& plaintext, int iKeyIndex = 0); | |
13 | + | |
14 | + std::string Decrypt(const std::string& ciphertext, int iKeyIndex = 0); | |
15 | + | |
16 | + void EncryptToFile(const std::string& plaintext, const std::string& ciphertext_file_name); | |
17 | + | |
18 | + std::string DecryptFromFile(const std::string& ciphertext_file_name); | |
19 | + | |
20 | + void EncryptFileToFile(const std::string& plaintext_file_name, const std::string& ciphertext_file_name); | |
21 | + | |
22 | + void DecryptFileToFile(const std::string& ciphertext_file_name, const std::string& plaintext_file_name); | |
23 | +} // AES_CBC | |
24 | + | |
25 | +#endif // ETRADECLIENT_UTILITY_OPENSSL_AES_CBC_H_INCLUDED | ... | ... |
card_file_tool/DLCardTool/password_machine.cpp
0 → 100644
1 | +#include "stdafx.h" | |
2 | + | |
3 | +#include "password_machine.h" | |
4 | + | |
5 | +#include <sstream> | |
6 | + | |
7 | +#include "mangerCmd.h" | |
8 | +#include "commonCmd.h" | |
9 | +#include "afxinet.h" | |
10 | + | |
11 | +PWDMachine::PWDMachine() : m_socket(-1)// "-1" indicates a invalid socket. | |
12 | +{} | |
13 | + | |
14 | +PWDMachine::~PWDMachine() | |
15 | +{ | |
16 | + Disconnect(); | |
17 | +} | |
18 | + | |
19 | +bool PWDMachine::Connect(const std::string& ip, uint32_t port) const | |
20 | +{ | |
21 | + m_socket = union_syj1001_connect(const_cast<char*>(ip.c_str()), port, 0); // 该函数的连接超时为20秒左右,因此不做重试. | |
22 | + return m_socket > 0; | |
23 | +} | |
24 | + | |
25 | +void PWDMachine::Disconnect() const | |
26 | +{ | |
27 | + if (m_socket > 0) | |
28 | + { | |
29 | + if (union_syj1001_disConnect(m_socket) < 0) | |
30 | + throw std::exception("关闭加密机失败!"); | |
31 | + } | |
32 | + m_socket = -1; // Reset. | |
33 | +} | |
34 | + | |
35 | +std::string PWDMachine::GetCardPassword(const std::string& key_idx, | |
36 | + const std::string& card_sn, | |
37 | + uint32_t timeout) const | |
38 | +{ | |
39 | + static const uint8_t MK_KEY_VAL = NULL; | |
40 | + static const uint8_t DISPERSE_COUNT = 2; // 离散次数 | |
41 | + static const uint8_t NEED_READ_CFG = 0; // 0:不从配置文件读取hsmIp、hsmPort、timeOut、hsmLenOfMsgHeader、isLenOfHsmMsg. | |
42 | + static const uint8_t MSG_HEADER_LEN = 8; // hsmLenOfMsgHeader. | |
43 | + static const uint8_t NEED_HSM_MSG_LEN = 1; // 是否需要报文长度 0:不需要 1:需要. | |
44 | + static const uint8_t DISPERSE_VAR_LEN = 16; // 离散变量的最大单位长度为16个字符. | |
45 | + | |
46 | + static const uint8_t KEY_VAL_LEN = 32; | |
47 | + typedef char NewKeyVal[KEY_VAL_LEN]; // MK加密下的过程密钥/子密钥密文, 长度为32个字符的字符数组。 | |
48 | + | |
49 | + static const uint8_t CHECK_VAL_LEN = 16; | |
50 | + typedef char ChkVal[CHECK_VAL_LEN]; // 过程密钥/子密钥的校验值, 长度为16个字符的字符数组。 | |
51 | + | |
52 | + if (card_sn.empty()) | |
53 | + throw std::exception("SN号为空!"); | |
54 | + | |
55 | + NewKeyVal new_key = { 0 }; | |
56 | + ChkVal chk_val = { 0 }; | |
57 | + int32_t key_len = union_syj1001_disperseKey(NULL, 0, timeout, NEED_READ_CFG, MSG_HEADER_LEN, NEED_HSM_MSG_LEN, m_socket, | |
58 | + const_cast<char*>(key_idx.c_str()), MK_KEY_VAL, new_key, chk_val, DISPERSE_COUNT, | |
59 | + card_sn.substr(0, DISPERSE_VAR_LEN).c_str(), card_sn.substr(DISPERSE_VAR_LEN, DISPERSE_VAR_LEN).c_str()); // 离散变量如果大于16字符,要把离散量拆成数组. | |
60 | + | |
61 | + if (key_len < 0) | |
62 | + { | |
63 | + std::stringstream err_msg; | |
64 | + err_msg << "获取秘钥失败, 秘钥标识: " << key_idx; | |
65 | + throw std::exception(err_msg.str().c_str()); | |
66 | + } | |
67 | + return std::string(new_key, key_len); | |
68 | +} | |
69 | + | |
70 | +//bool PWDMachine::ReadConfig() | |
71 | +//{ | |
72 | +// bool bResult = false; | |
73 | +// | |
74 | +// CString sXMLPath = GetModulePath() + L"PWMConfig.xml"; | |
75 | +// | |
76 | +// TiXmlDocument xmlDoc(wstr_2_str(sXMLPath.GetBuffer()).c_str()); | |
77 | +// if (xmlDoc.LoadFile()) | |
78 | +// { | |
79 | +// try | |
80 | +// { | |
81 | +// bResult = true; | |
82 | +// TiXmlElement *pRootEle = xmlDoc.RootElement(); | |
83 | +// TiXmlElement *pPWMIP = pRootEle->FirstChildElement(); | |
84 | +// m_sPWMIP = pPWMIP->GetText(); | |
85 | +// TiXmlElement *pPWMPort = pPWMIP->NextSiblingElement(); | |
86 | +// std::string sPWMPort = pPWMPort->GetText(); | |
87 | +// m_u32PWMPort = atoi(sPWMPort.c_str()); | |
88 | +// } | |
89 | +// catch (std::exception &e) | |
90 | +// { | |
91 | +// bResult = false; | |
92 | +// } | |
93 | +// } | |
94 | +// | |
95 | +// return bResult; | |
96 | +//} | |
97 | + | |
98 | +CString PWDMachine::GetModulePath() | |
99 | +{ | |
100 | + CString sPath; | |
101 | + | |
102 | + TCHAR szPath[MAX_PATH]; | |
103 | + GetModuleFileName(NULL, szPath, MAX_PATH); | |
104 | + CString sMudolePath = szPath; | |
105 | + CString sMudoleName = AfxGetAppName(); | |
106 | + sPath = sMudolePath.Left(sMudolePath.GetLength() - sMudoleName.GetLength() - 4); | |
107 | + return sPath; | |
108 | +} | |
109 | + | |
110 | +std::string PWDMachine::GetPassword(const std::string& key_idx, const std::string& card_sn, uint32_t timeout, std::string sPWMIP, | |
111 | + uint32_t u32PWMPort) const | |
112 | +{ | |
113 | + if (!Connect(sPWMIP, u32PWMPort)) | |
114 | + { | |
115 | + throw std::exception("加密机连接失败!"); | |
116 | + } | |
117 | + | |
118 | + std::string sPassWord = GetCardPassword(key_idx, card_sn, timeout); | |
119 | + | |
120 | + Disconnect(); | |
121 | + | |
122 | + return sPassWord; | |
123 | +} | |
0 | 124 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/password_machine.h
0 → 100644
1 | +#ifndef ETRADECLIENT_HARDWARE_PASSWORD_MACHINE_H_INCLUDED | |
2 | +#define ETRADECLIENT_HARDWARE_PASSWORD_MACHINE_H_INCLUDED | |
3 | + | |
4 | +/*Password machine is used to calculate the password for verifying the DILI card. | |
5 | +*/ | |
6 | + | |
7 | +/* | |
8 | +密码机信息: | |
9 | +生产厂商:广州江南科友科技股份有限公司 | |
10 | +型号:(未知) | |
11 | +*/ | |
12 | + | |
13 | +#include <string> | |
14 | +#include <cstdint> | |
15 | +#include "tinyxml.h" | |
16 | + | |
17 | +class PWDMachine | |
18 | +{ | |
19 | +public: | |
20 | + PWDMachine(); | |
21 | + ~PWDMachine(); | |
22 | + | |
23 | + //bool ReadConfig(); | |
24 | + | |
25 | + std::string GetPassword(const std::string& key_idx, // 密钥索引 | |
26 | + const std::string& card_sn, // 卡序列号(卡片内码),用作离散数据 | |
27 | + uint32_t timeout, | |
28 | + std::string sPWMIP, | |
29 | + uint32_t u32PWMPort) const; // 单位:毫秒 | |
30 | + | |
31 | +private: | |
32 | + mutable int32_t m_socket; | |
33 | + | |
34 | + CString GetModulePath(); | |
35 | + //std::string m_sPWMIP; | |
36 | + //uint32_t m_u32PWMPort; | |
37 | + | |
38 | + bool Connect(const std::string& ip, uint32_t port) const; | |
39 | + void Disconnect() const; | |
40 | + std::string GetCardPassword(const std::string& key_idx, // 密钥索引 | |
41 | + const std::string& card_sn, // 卡序列号(卡片内码),用作离散数据 | |
42 | + uint32_t timeout) const; // 单位:毫秒 | |
43 | + | |
44 | +}; // PWDMachine | |
45 | + | |
46 | +#endif // ETRADECLIENT_HARDWARE_PASSWORD_MACHINE_H_INCLUDED | ... | ... |
card_file_tool/DLCardTool/res/DLCardTool.ico
0 → 100644
No preview for this file type
card_file_tool/DLCardTool/res/DLCardTool.rc2
0 → 100644
card_file_tool/DLCardTool/res/DLLogo.ico
0 → 100644
No preview for this file type
card_file_tool/DLCardTool/res/files.png
0 → 100644
1002 Bytes
card_file_tool/DLCardTool/resource.h
0 → 100644
card_file_tool/DLCardTool/stdafx.cpp
0 → 100644
card_file_tool/DLCardTool/stdafx.h
0 → 100644
1 | + | |
2 | +// stdafx.h : 标准系统包含文件的包含文件, | |
3 | +// 或是经常使用但不常更改的 | |
4 | +// 特定于项目的包含文件 | |
5 | + | |
6 | +#pragma once | |
7 | + | |
8 | +#ifndef VC_EXTRALEAN | |
9 | +#define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 | |
10 | +#endif | |
11 | + | |
12 | +#include "targetver.h" | |
13 | + | |
14 | +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 | |
15 | + | |
16 | +// 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏 | |
17 | +#define _AFX_ALL_WARNINGS | |
18 | + | |
19 | +#include <afxwin.h> // MFC 核心组件和标准组件 | |
20 | +#include <afxext.h> // MFC 扩展 | |
21 | + | |
22 | + | |
23 | +#include <afxdisp.h> // MFC 自动化类 | |
24 | + | |
25 | + | |
26 | + | |
27 | +#ifndef _AFX_NO_OLE_SUPPORT | |
28 | +#include <afxdtctl.h> // MFC 对 Internet Explorer 4 公共控件的支持 | |
29 | +#endif | |
30 | +#ifndef _AFX_NO_AFXCMN_SUPPORT | |
31 | +#include <afxcmn.h> // MFC 对 Windows 公共控件的支持 | |
32 | +#endif // _AFX_NO_AFXCMN_SUPPORT | |
33 | + | |
34 | +#include <afxcontrolbars.h> // 功能区和控件条的 MFC 支持 | |
35 | + | |
36 | +#include "DLTools.h" | |
37 | +#include "DLCardManager.h" | |
38 | +#include "openssl_aes_cbc.h" | |
39 | +#include "string_converter.h" | |
40 | + | |
41 | +#include <boost/algorithm/string.hpp>" | |
42 | +#include <boost/property_tree/ptree.hpp> | |
43 | +#include <boost/filesystem.hpp> | |
44 | +#include "json_parser.hpp" // WARNIING! Make sure to include our patched version. | |
45 | +#include "DLDes.h" | |
46 | + | |
47 | +#include <io.h> | |
48 | +#include <direct.h> | |
49 | + | |
50 | + | |
51 | + | |
52 | + | |
53 | +#ifdef _UNICODE | |
54 | +#if defined _M_IX86 | |
55 | +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
56 | +#elif defined _M_X64 | |
57 | +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
58 | +#else | |
59 | +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") | |
60 | +#endif | |
61 | +#endif | |
62 | + | |
63 | + | ... | ... |
card_file_tool/DLCardTool/string_converter.cpp
0 → 100644
1 | +#include "stdafx.h" | |
2 | + | |
3 | + | |
4 | +#include <locale> | |
5 | +#include <codecvt> | |
6 | + | |
7 | +typedef std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter_t; | |
8 | +static utf8_converter_t utf8_converter; | |
9 | + | |
10 | +typedef std::codecvt<wchar_t, char, std::mbstate_t> cvt; // Convert Unicode & GBK | |
11 | +static std::wstring_convert<cvt> gbk_converter(new cvt("CHS")); // Chinese (Simplified)_People's Republic of China.936 | |
12 | + | |
13 | +std::string wstr_2_str(const std::wstring& wstr) | |
14 | +{ | |
15 | + return utf8_converter.to_bytes(wstr); | |
16 | +} | |
17 | +std::string wstr_2_str(const wchar_t* wstr) | |
18 | +{ | |
19 | + return utf8_converter.to_bytes(wstr); | |
20 | +} | |
21 | +std::string wstr_2_str(const wchar_t* first, const wchar_t* last) | |
22 | +{ | |
23 | + return utf8_converter.to_bytes(first, last); | |
24 | +} | |
25 | + | |
26 | +std::wstring str_2_wstr(const std::string& str) | |
27 | +{ | |
28 | + return utf8_converter.from_bytes(str); | |
29 | +} | |
30 | +std::wstring str_2_wstr(const char* str) | |
31 | +{ | |
32 | + return utf8_converter.from_bytes(str); | |
33 | +} | |
34 | +std::wstring str_2_wstr(const char* first, const char* last) | |
35 | +{ | |
36 | + return utf8_converter.from_bytes(first, last); | |
37 | +} | |
38 | + | |
39 | +std::wstring gbk_2_wstr(const std::string& gbk_str) | |
40 | +{ | |
41 | + return gbk_converter.from_bytes(gbk_str); | |
42 | +} | |
43 | + | |
44 | +std::string wstr_2_gbk(const std::wstring& wstr) | |
45 | +{ | |
46 | + return gbk_converter.to_bytes(wstr); | |
47 | +} | |
0 | 48 | \ No newline at end of file | ... | ... |
card_file_tool/DLCardTool/string_converter.h
0 → 100644
1 | +#ifndef ETRADECLIENT_UTILITY_STRING_CONVERTER_H_INCLUDED | |
2 | +#define ETRADECLIENT_UTILITY_STRING_CONVERTER_H_INCLUDED | |
3 | + | |
4 | +#include <string> | |
5 | + | |
6 | +/*These APIs can be used to make conversion between Unicode string and UTF-8 string. | |
7 | +For example: | |
8 | +std::wstring ws = L"ÖÐÎÄ"; // 'ws' is Unicode string with value of '0x4e2d' & '0x6587'. | |
9 | +std::string s = wstr_2_str(ws); // 's' is UTF-8 string with value of '0xe4b8ad' & '0xe69687'. | |
10 | +std::wstring ws_ = str_2_wstr(s); // 'ws_' is Unicode string with value of '0x4e2d' & '0x6587'. | |
11 | +*/ | |
12 | + | |
13 | +std::string wstr_2_str(const std::wstring& wstr); | |
14 | +std::string wstr_2_str(const wchar_t* wstr); | |
15 | +std::string wstr_2_str(const wchar_t* first, const wchar_t* last); | |
16 | + | |
17 | +std::wstring str_2_wstr(const std::string& str); | |
18 | +std::wstring str_2_wstr(const char* str); | |
19 | +std::wstring str_2_wstr(const char* first, const char* last); | |
20 | + | |
21 | +/*This API is specially used to do conversion between Chinese characters in GBK encoding & Unicode encoding.*/ | |
22 | +std::wstring gbk_2_wstr(const std::string& gbk_str); | |
23 | +std::string wstr_2_gbk(const std::wstring& wstr); | |
24 | + | |
25 | +#endif // ETRADECLIENT_UTILITY_STRING_CONVERTER_H_INCLUDED | ... | ... |
card_file_tool/DLCardTool/targetver.h
0 → 100644
card_file_tool/DLCardTool/tinystr.cpp
0 → 100644
1 | +/* | |
2 | +www.sourceforge.net/projects/tinyxml | |
3 | + | |
4 | +This software is provided 'as-is', without any express or implied | |
5 | +warranty. In no event will the authors be held liable for any | |
6 | +damages arising from the use of this software. | |
7 | + | |
8 | +Permission is granted to anyone to use this software for any | |
9 | +purpose, including commercial applications, and to alter it and | |
10 | +redistribute it freely, subject to the following restrictions: | |
11 | + | |
12 | +1. The origin of this software must not be misrepresented; you must | |
13 | +not claim that you wrote the original software. If you use this | |
14 | +software in a product, an acknowledgment in the product documentation | |
15 | +would be appreciated but is not required. | |
16 | + | |
17 | +2. Altered source versions must be plainly marked as such, and | |
18 | +must not be misrepresented as being the original software. | |
19 | + | |
20 | +3. This notice may not be removed or altered from any source | |
21 | +distribution. | |
22 | +*/ | |
23 | +#include "stdafx.h" | |
24 | + | |
25 | +#ifndef TIXML_USE_STL | |
26 | + | |
27 | +#include "tinystr.h" | |
28 | + | |
29 | + | |
30 | +// Error value for find primitive | |
31 | +const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1); | |
32 | + | |
33 | + | |
34 | +// Null rep. | |
35 | +TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; | |
36 | + | |
37 | + | |
38 | +void TiXmlString::reserve (size_type cap) | |
39 | +{ | |
40 | + if (cap > capacity()) | |
41 | + { | |
42 | + TiXmlString tmp; | |
43 | + tmp.init(length(), cap); | |
44 | + memcpy(tmp.start(), data(), length()); | |
45 | + swap(tmp); | |
46 | + } | |
47 | +} | |
48 | + | |
49 | + | |
50 | +TiXmlString& TiXmlString::assign(const char* str, size_type len) | |
51 | +{ | |
52 | + size_type cap = capacity(); | |
53 | + if (len > cap || cap > 3*(len + 8)) | |
54 | + { | |
55 | + TiXmlString tmp; | |
56 | + tmp.init(len); | |
57 | + memcpy(tmp.start(), str, len); | |
58 | + swap(tmp); | |
59 | + } | |
60 | + else | |
61 | + { | |
62 | + memmove(start(), str, len); | |
63 | + set_size(len); | |
64 | + } | |
65 | + return *this; | |
66 | +} | |
67 | + | |
68 | + | |
69 | +TiXmlString& TiXmlString::append(const char* str, size_type len) | |
70 | +{ | |
71 | + size_type newsize = length() + len; | |
72 | + if (newsize > capacity()) | |
73 | + { | |
74 | + reserve (newsize + capacity()); | |
75 | + } | |
76 | + memmove(finish(), str, len); | |
77 | + set_size(newsize); | |
78 | + return *this; | |
79 | +} | |
80 | + | |
81 | + | |
82 | +TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) | |
83 | +{ | |
84 | + TiXmlString tmp; | |
85 | + tmp.reserve(a.length() + b.length()); | |
86 | + tmp += a; | |
87 | + tmp += b; | |
88 | + return tmp; | |
89 | +} | |
90 | + | |
91 | +TiXmlString operator + (const TiXmlString & a, const char* b) | |
92 | +{ | |
93 | + TiXmlString tmp; | |
94 | + TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) ); | |
95 | + tmp.reserve(a.length() + b_len); | |
96 | + tmp += a; | |
97 | + tmp.append(b, b_len); | |
98 | + return tmp; | |
99 | +} | |
100 | + | |
101 | +TiXmlString operator + (const char* a, const TiXmlString & b) | |
102 | +{ | |
103 | + TiXmlString tmp; | |
104 | + TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) ); | |
105 | + tmp.reserve(a_len + b.length()); | |
106 | + tmp.append(a, a_len); | |
107 | + tmp += b; | |
108 | + return tmp; | |
109 | +} | |
110 | + | |
111 | + | |
112 | +#endif // TIXML_USE_STL | ... | ... |
card_file_tool/DLCardTool/tinystr.h
0 → 100644
1 | +/* | |
2 | +www.sourceforge.net/projects/tinyxml | |
3 | + | |
4 | +This software is provided 'as-is', without any express or implied | |
5 | +warranty. In no event will the authors be held liable for any | |
6 | +damages arising from the use of this software. | |
7 | + | |
8 | +Permission is granted to anyone to use this software for any | |
9 | +purpose, including commercial applications, and to alter it and | |
10 | +redistribute it freely, subject to the following restrictions: | |
11 | + | |
12 | +1. The origin of this software must not be misrepresented; you must | |
13 | +not claim that you wrote the original software. If you use this | |
14 | +software in a product, an acknowledgment in the product documentation | |
15 | +would be appreciated but is not required. | |
16 | + | |
17 | +2. Altered source versions must be plainly marked as such, and | |
18 | +must not be misrepresented as being the original software. | |
19 | + | |
20 | +3. This notice may not be removed or altered from any source | |
21 | +distribution. | |
22 | +*/ | |
23 | + | |
24 | + | |
25 | +#ifndef TIXML_USE_STL | |
26 | + | |
27 | +#ifndef TIXML_STRING_INCLUDED | |
28 | +#define TIXML_STRING_INCLUDED | |
29 | + | |
30 | +#include <assert.h> | |
31 | +#include <string.h> | |
32 | + | |
33 | +/* The support for explicit isn't that universal, and it isn't really | |
34 | + required - it is used to check that the TiXmlString class isn't incorrectly | |
35 | + used. Be nice to old compilers and macro it here: | |
36 | +*/ | |
37 | +#if defined(_MSC_VER) && (_MSC_VER >= 1200 ) | |
38 | + // Microsoft visual studio, version 6 and higher. | |
39 | + #define TIXML_EXPLICIT explicit | |
40 | +#elif defined(__GNUC__) && (__GNUC__ >= 3 ) | |
41 | + // GCC version 3 and higher.s | |
42 | + #define TIXML_EXPLICIT explicit | |
43 | +#else | |
44 | + #define TIXML_EXPLICIT | |
45 | +#endif | |
46 | + | |
47 | + | |
48 | +/* | |
49 | + TiXmlString is an emulation of a subset of the std::string template. | |
50 | + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. | |
51 | + Only the member functions relevant to the TinyXML project have been implemented. | |
52 | + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase | |
53 | + a string and there's no more room, we allocate a buffer twice as big as we need. | |
54 | +*/ | |
55 | +class TiXmlString | |
56 | +{ | |
57 | + public : | |
58 | + // The size type used | |
59 | + typedef size_t size_type; | |
60 | + | |
61 | + // Error value for find primitive | |
62 | + static const size_type npos; // = -1; | |
63 | + | |
64 | + | |
65 | + // TiXmlString empty constructor | |
66 | + TiXmlString () : rep_(&nullrep_) | |
67 | + { | |
68 | + } | |
69 | + | |
70 | + // TiXmlString copy constructor | |
71 | + TiXmlString ( const TiXmlString & copy) : rep_(0) | |
72 | + { | |
73 | + init(copy.length()); | |
74 | + memcpy(start(), copy.data(), length()); | |
75 | + } | |
76 | + | |
77 | + // TiXmlString constructor, based on a string | |
78 | + TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0) | |
79 | + { | |
80 | + init( static_cast<size_type>( strlen(copy) )); | |
81 | + memcpy(start(), copy, length()); | |
82 | + } | |
83 | + | |
84 | + // TiXmlString constructor, based on a string | |
85 | + TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0) | |
86 | + { | |
87 | + init(len); | |
88 | + memcpy(start(), str, len); | |
89 | + } | |
90 | + | |
91 | + // TiXmlString destructor | |
92 | + ~TiXmlString () | |
93 | + { | |
94 | + quit(); | |
95 | + } | |
96 | + | |
97 | + TiXmlString& operator = (const char * copy) | |
98 | + { | |
99 | + return assign( copy, (size_type)strlen(copy)); | |
100 | + } | |
101 | + | |
102 | + TiXmlString& operator = (const TiXmlString & copy) | |
103 | + { | |
104 | + return assign(copy.start(), copy.length()); | |
105 | + } | |
106 | + | |
107 | + | |
108 | + // += operator. Maps to append | |
109 | + TiXmlString& operator += (const char * suffix) | |
110 | + { | |
111 | + return append(suffix, static_cast<size_type>( strlen(suffix) )); | |
112 | + } | |
113 | + | |
114 | + // += operator. Maps to append | |
115 | + TiXmlString& operator += (char single) | |
116 | + { | |
117 | + return append(&single, 1); | |
118 | + } | |
119 | + | |
120 | + // += operator. Maps to append | |
121 | + TiXmlString& operator += (const TiXmlString & suffix) | |
122 | + { | |
123 | + return append(suffix.data(), suffix.length()); | |
124 | + } | |
125 | + | |
126 | + | |
127 | + // Convert a TiXmlString into a null-terminated char * | |
128 | + const char * c_str () const { return rep_->str; } | |
129 | + | |
130 | + // Convert a TiXmlString into a char * (need not be null terminated). | |
131 | + const char * data () const { return rep_->str; } | |
132 | + | |
133 | + // Return the length of a TiXmlString | |
134 | + size_type length () const { return rep_->size; } | |
135 | + | |
136 | + // Alias for length() | |
137 | + size_type size () const { return rep_->size; } | |
138 | + | |
139 | + // Checks if a TiXmlString is empty | |
140 | + bool empty () const { return rep_->size == 0; } | |
141 | + | |
142 | + // Return capacity of string | |
143 | + size_type capacity () const { return rep_->capacity; } | |
144 | + | |
145 | + | |
146 | + // single char extraction | |
147 | + const char& at (size_type index) const | |
148 | + { | |
149 | + assert( index < length() ); | |
150 | + return rep_->str[ index ]; | |
151 | + } | |
152 | + | |
153 | + // [] operator | |
154 | + char& operator [] (size_type index) const | |
155 | + { | |
156 | + assert( index < length() ); | |
157 | + return rep_->str[ index ]; | |
158 | + } | |
159 | + | |
160 | + // find a char in a string. Return TiXmlString::npos if not found | |
161 | + size_type find (char lookup) const | |
162 | + { | |
163 | + return find(lookup, 0); | |
164 | + } | |
165 | + | |
166 | + // find a char in a string from an offset. Return TiXmlString::npos if not found | |
167 | + size_type find (char tofind, size_type offset) const | |
168 | + { | |
169 | + if (offset >= length()) return npos; | |
170 | + | |
171 | + for (const char* p = c_str() + offset; *p != '\0'; ++p) | |
172 | + { | |
173 | + if (*p == tofind) return static_cast< size_type >( p - c_str() ); | |
174 | + } | |
175 | + return npos; | |
176 | + } | |
177 | + | |
178 | + void clear () | |
179 | + { | |
180 | + //Lee: | |
181 | + //The original was just too strange, though correct: | |
182 | + // TiXmlString().swap(*this); | |
183 | + //Instead use the quit & re-init: | |
184 | + quit(); | |
185 | + init(0,0); | |
186 | + } | |
187 | + | |
188 | + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this | |
189 | + function DOES NOT clear the content of the TiXmlString if any exists. | |
190 | + */ | |
191 | + void reserve (size_type cap); | |
192 | + | |
193 | + TiXmlString& assign (const char* str, size_type len); | |
194 | + | |
195 | + TiXmlString& append (const char* str, size_type len); | |
196 | + | |
197 | + void swap (TiXmlString& other) | |
198 | + { | |
199 | + Rep* r = rep_; | |
200 | + rep_ = other.rep_; | |
201 | + other.rep_ = r; | |
202 | + } | |
203 | + | |
204 | + private: | |
205 | + | |
206 | + void init(size_type sz) { init(sz, sz); } | |
207 | + void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } | |
208 | + char* start() const { return rep_->str; } | |
209 | + char* finish() const { return rep_->str + rep_->size; } | |
210 | + | |
211 | + struct Rep | |
212 | + { | |
213 | + size_type size, capacity; | |
214 | + char str[1]; | |
215 | + }; | |
216 | + | |
217 | + void init(size_type sz, size_type cap) | |
218 | + { | |
219 | + if (cap) | |
220 | + { | |
221 | + // Lee: the original form: | |
222 | + // rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap)); | |
223 | + // doesn't work in some cases of new being overloaded. Switching | |
224 | + // to the normal allocation, although use an 'int' for systems | |
225 | + // that are overly picky about structure alignment. | |
226 | + const size_type bytesNeeded = sizeof(Rep) + cap; | |
227 | + const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); | |
228 | + rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] ); | |
229 | + | |
230 | + rep_->str[ rep_->size = sz ] = '\0'; | |
231 | + rep_->capacity = cap; | |
232 | + } | |
233 | + else | |
234 | + { | |
235 | + rep_ = &nullrep_; | |
236 | + } | |
237 | + } | |
238 | + | |
239 | + void quit() | |
240 | + { | |
241 | + if (rep_ != &nullrep_) | |
242 | + { | |
243 | + // The rep_ is really an array of ints. (see the allocator, above). | |
244 | + // Cast it back before delete, so the compiler won't incorrectly call destructors. | |
245 | + delete [] ( reinterpret_cast<int*>( rep_ ) ); | |
246 | + } | |
247 | + } | |
248 | + | |
249 | + Rep * rep_; | |
250 | + static Rep nullrep_; | |
251 | + | |
252 | +} ; | |
253 | + | |
254 | + | |
255 | +inline bool operator == (const TiXmlString & a, const TiXmlString & b) | |
256 | +{ | |
257 | + return ( a.length() == b.length() ) // optimization on some platforms | |
258 | + && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare | |
259 | +} | |
260 | +inline bool operator < (const TiXmlString & a, const TiXmlString & b) | |
261 | +{ | |
262 | + return strcmp(a.c_str(), b.c_str()) < 0; | |
263 | +} | |
264 | + | |
265 | +inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } | |
266 | +inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } | |
267 | +inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } | |
268 | +inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } | |
269 | + | |
270 | +inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } | |
271 | +inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } | |
272 | +inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } | |
273 | +inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } | |
274 | + | |
275 | +TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); | |
276 | +TiXmlString operator + (const TiXmlString & a, const char* b); | |
277 | +TiXmlString operator + (const char* a, const TiXmlString & b); | |
278 | + | |
279 | + | |
280 | +/* | |
281 | + TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. | |
282 | + Only the operators that we need for TinyXML have been developped. | |
283 | +*/ | |
284 | +class TiXmlOutStream : public TiXmlString | |
285 | +{ | |
286 | +public : | |
287 | + | |
288 | + // TiXmlOutStream << operator. | |
289 | + TiXmlOutStream & operator << (const TiXmlString & in) | |
290 | + { | |
291 | + *this += in; | |
292 | + return *this; | |
293 | + } | |
294 | + | |
295 | + // TiXmlOutStream << operator. | |
296 | + TiXmlOutStream & operator << (const char * in) | |
297 | + { | |
298 | + *this += in; | |
299 | + return *this; | |
300 | + } | |
301 | + | |
302 | +} ; | |
303 | + | |
304 | +#endif // TIXML_STRING_INCLUDED | |
305 | +#endif // TIXML_USE_STL | ... | ... |