提交 8a1defaa 编写于 作者: A arv000

feat: 更新SM2WithSM3签名校验测试代码

 更新SM2WithSM3签名校验测试代码

Log:  更新SM2WithSM3签名校验测试代码
上级 11ec7a54
cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
project(Test)
# 一般当前目录设置为直接包含目录
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# 添加外部库的头文件目录
include_directories(
/home/arv000/openssl/include
)
link_directories(/home/arv000/openssl/lib64)
# 生成可执行程序
add_executable(Test main.cc)
# 链接QT使用的库文件
target_link_libraries (Test libcrypto.a libssl.a pthread dl)
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/err.h>
#include <string.h>
#include <stdio.h>
#include <openssl/pem.h>
#include <fstream>
#include <openssl/sm3.h>
int main(void)
{
EVP_MD_CTX *cmd_ctx = EVP_MD_CTX_new();
EVP_PKEY_CTX* pctx = nullptr; // Owned by |ctx|.
const char* filePath = "/media/arv000/c19ee280-30c9-43bc-a890-05e8c96984bc/00-work/01-bug/证书验证问题/国密SM2服务器根证书V3_client.pem";
const char* signature_value_bytes_filePath = "/home/arv000/signature_value_bytes.der";
const char* signed_data_filePath = "/home/arv000/signed_data.der";
const EVP_MD *digest = EVP_sm3();
// 读取公钥
FILE* file = fopen(filePath, "rb");
if(nullptr == file){
printf("public_key opens is failed ;\r\n");
}
EVP_PKEY* public_key = PEM_read_PUBKEY(file, nullptr,nullptr,nullptr);
if(nullptr == public_key){
printf("public_key is null ;\r\n");
}
fclose(file);
// 读取签名内容
FILE* file2 = fopen(signature_value_bytes_filePath, "rb");
// 获取文件大小
fseek(file2, 0, SEEK_END);
long signature_value_bytes_length = ftell(file2);
fseek(file2, 0, SEEK_SET);
char* signature_value_bytes = (char*)malloc(signature_value_bytes_length);
memset(signature_value_bytes,0,signature_value_bytes_length);
fread(signature_value_bytes, 1, signature_value_bytes_length, file2);
fclose(file2);
// 读取签名值内容
FILE* file3 = fopen(signed_data_filePath, "rb");
// 获取文件大小
fseek(file3, 0, SEEK_END);
long signed_data_length = ftell(file3);
fseek(file3, 0, SEEK_SET);
char* signed_data = (char*)malloc(signed_data_length);
memset(signed_data,0,signed_data_length);
fread(signed_data, 1, signed_data_length, file3);
fclose(file3);
if (!EVP_DigestVerifyInit(cmd_ctx, &pctx, digest, nullptr, public_key))
{
printf("EVP_DigestVerifyInit failed ;\r\n");
return false;
}
if (!EVP_DigestVerifyUpdate(cmd_ctx, signed_data,
signed_data_length)) {
printf("EVP_DigestVerifyUpdate failed ;\r\n");
return false;
}
bool ret =
1 == EVP_DigestVerifyFinal(cmd_ctx, reinterpret_cast<const unsigned char*>(signature_value_bytes),
signature_value_bytes_length);
printf("ret = %d ;\r\n",ret);
return 0;
}
\ No newline at end of file
0D hjwFlҵDY
[0/#UtȜ ^mmT|'#ohv{$GVl 
\ No newline at end of file
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE76S2wS2wnzVaso2EhpAp9ALrJWkB
scBkpunMEBvwJAwWnWG9SwaefXqnjj1EBiZySYnUl4ZHRsWxXCgcLwdLnw==
-----END PUBLIC KEY-----
#-------------------------------------------------
#
# Project created by QtCreator 2023-11-13T20:49:15
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QWebChannelJS
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
#include "jsapiproxy.h"
JSApiProxy::JSApiProxy(QObject *parent) : QObject(parent)
{
}
#ifndef JSAPIPROXY_H
#define JSAPIPROXY_H
#include <QObject>
class JSApiProxy : public QObject
{
Q_OBJECT
public:
explicit JSApiProxy(QObject *parent = nullptr);
signals:
public slots:
};
#endif // JSAPIPROXY_H
\ No newline at end of file
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
}
MainWindow::~MainWindow()
{
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
<!DOCTYPE RCC>
<RCC version="1.0"/>
.btn{
background: red;
}
\ No newline at end of file
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/index.js"></script>
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<button class="btn" onclick="cl();">按钮</button>
</html>
function cl(){
alert("asdf");
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册