0%

ecc windows api 使用

签名

签名文件

1
.\sign_file.exe -d -r .\driver_test_key\ecc_priv_key -b <待签文件路径> -e <签名后的文件路径> -s

验证是否验签正常

1
.\sign_file.exe -d -u .\driver_test_key\ecc_pub_key  -e <签名后的文件路径> -v

验签

验签接口 verifyFile

1
2
3
4
5
6
7
8
9
10
#pragma once
/*
* ecc verify file to check if sign by specific priv key
* input:
* fp: input file pointer by fopen
* fileSize: file size by stat.st_size
* out:
* return 0: verify success, -1: verify fail
*/
int verifyFile(FILE* fp, int fileSize);

上面的实现代码就是VerifyLibApi.h的内容

使用示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include "VerifyLibApi.h"

int main()
{
struct stat dat_stat;
const char* dat_path = "C:\\Users\\1\\Documents\\test.dat";

if (stat(dat_path, &dat_stat) != 0) {
printf("stat %s failed:%s\n", dat_path, strerror(errno));
return -1;
}

FILE* fp = fopen(dat_path, "rb");
if (fp == NULL)
{
printf("can't read_file_bytes\n");
return -1;
}
if (0 != verifyFile(fp, dat_stat.st_size))
{
printf("verifyFile failed!\n");
if (fp != NULL) fclose(fp);
return -1;
}
if (fp != NULL) fclose(fp);
return 0;
}

VisualStudio 使用示例

上面使用的接口输出的库是静态库VerifyLib.lib

在VisualStudio 开发时, 可以按下面的示例配置使用该库

首先lib库给出的有两个版本, 分别是debug版本和release版本用的

debug和release都需要配置

debug配置示例

VC++目录 -> 库目录 中添加debug版本的库所在的文件夹的路径

image-20220314103457471

链接器->输入->附加依赖项 中添加对应的VerifyLib库的文件名

image-20220314103547303

release 版本的配置过程跟debug版本一样, 不再赘述