当前位置: 首页 > news >正文

杭州哪些做网站公司做网站用软件

杭州哪些做网站公司,做网站用软件,河南新闻头条最新消息,张家口建设厅官方网站文章目录 openssl3.2 - 官方demo学习 - signature - rsa_pss_hash.c概述笔记END openssl3.2 - 官方demo学习 - signature - rsa_pss_hash.c 概述 对私钥对明文做签名(摘要算法为SHA256) 用公钥对密文做验签(摘要算法为SHA256) 笔记 /*! \file rsa_pss_hash.c \note openss…

文章目录

    • openssl3.2 - 官方demo学习 - signature - rsa_pss_hash.c
    • 概述
    • 笔记
    • END

openssl3.2 - 官方demo学习 - signature - rsa_pss_hash.c

概述

对私钥对明文做签名(摘要算法为SHA256)
用公钥对密文做验签(摘要算法为SHA256)

笔记

/*!
\file rsa_pss_hash.c
\note 
openssl3.2 - 官方demo学习 - signature - rsa_pss_hash.c对私钥对明文做签名(摘要算法为SHA256)
用公钥对密文做验签(摘要算法为SHA256)
*//** Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.** Licensed under the Apache License 2.0 (the "License").  You may not use* this file except in compliance with the License.  You can obtain a copy* in the file LICENSE in the source distribution or at* https://www.openssl.org/source/license.html*/#include <stdio.h>
#include <stdlib.h>
#include <openssl/core_names.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <openssl/params.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include "rsa_pss.h"#include "my_openSSL_lib.h"/* The data to be signed. This will be hashed. */
static const char test_message[] ="This is an example message to be signed.";/* A property query used for selecting algorithm implementations. */
static const char *propq = NULL;/** This function demonstrates RSA signing of an arbitrary-length message.* Hashing is performed automatically. In this example, SHA-256 is used. If you* have already hashed your message and simply want to sign the hash directly,* see rsa_pss_direct.c.*/
static int sign(OSSL_LIB_CTX *libctx, unsigned char **sig, size_t *sig_len)
{int ret = 0;EVP_PKEY *pkey = NULL;EVP_MD_CTX *mctx = NULL;OSSL_PARAM params[2], *p = params;const unsigned char *ppriv_key = NULL;*sig = NULL;/* Load DER-encoded RSA private key. */ppriv_key = rsa_priv_key;pkey = d2i_PrivateKey_ex(EVP_PKEY_RSA, NULL, &ppriv_key,sizeof(rsa_priv_key), libctx, propq);if (pkey == NULL) {fprintf(stderr, "Failed to load private key\n");goto end;}/* Create MD context used for signing. */mctx = EVP_MD_CTX_new();if (mctx == NULL) {fprintf(stderr, "Failed to create MD context\n");goto end;}/* Initialize MD context for signing. */*p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE,OSSL_PKEY_RSA_PAD_MODE_PSS, 0);*p = OSSL_PARAM_construct_end();if (EVP_DigestSignInit_ex(mctx, NULL, "SHA256", libctx, propq,pkey, params) == 0) {fprintf(stderr, "Failed to initialize signing context\n");goto end;}/** Feed data to be signed into the algorithm. This may* be called multiple times.*/if (EVP_DigestSignUpdate(mctx, test_message, sizeof(test_message)) == 0) {fprintf(stderr, "Failed to hash message into signing context\n");goto end;}/* Determine signature length. */if (EVP_DigestSignFinal(mctx, NULL, sig_len) == 0) {fprintf(stderr, "Failed to get signature length\n");goto end;}/* Allocate memory for signature. */*sig = OPENSSL_malloc(*sig_len);if (*sig == NULL) {fprintf(stderr, "Failed to allocate memory for signature\n");goto end;}/* Generate signature. */if (EVP_DigestSignFinal(mctx, *sig, sig_len) == 0) {fprintf(stderr, "Failed to sign\n");goto end;}ret = 1;
end:EVP_MD_CTX_free(mctx);EVP_PKEY_free(pkey);if (ret == 0)OPENSSL_free(*sig);return ret;
}/** This function demonstrates verification of an RSA signature over an* arbitrary-length message using the PSS signature scheme. Hashing is performed* automatically.*/
static int verify(OSSL_LIB_CTX *libctx, const unsigned char *sig, size_t sig_len)
{int ret = 0;EVP_PKEY *pkey = NULL;EVP_MD_CTX *mctx = NULL;OSSL_PARAM params[2], *p = params;const unsigned char *ppub_key = NULL;/* Load DER-encoded RSA public key. */ppub_key = rsa_pub_key;pkey = d2i_PublicKey(EVP_PKEY_RSA, NULL, &ppub_key, sizeof(rsa_pub_key));if (pkey == NULL) {fprintf(stderr, "Failed to load public key\n");goto end;}/* Create MD context used for verification. */mctx = EVP_MD_CTX_new();if (mctx == NULL) {fprintf(stderr, "Failed to create MD context\n");goto end;}/* Initialize MD context for verification. */*p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE,OSSL_PKEY_RSA_PAD_MODE_PSS, 0);*p = OSSL_PARAM_construct_end();if (EVP_DigestVerifyInit_ex(mctx, NULL, "SHA256", libctx, propq,pkey, params) == 0) {fprintf(stderr, "Failed to initialize signing context\n");goto end;}/** Feed data to be signed into the algorithm. This may* be called multiple times.*/if (EVP_DigestVerifyUpdate(mctx, test_message, sizeof(test_message)) == 0) {fprintf(stderr, "Failed to hash message into signing context\n");goto end;}/* Verify signature. */if (EVP_DigestVerifyFinal(mctx, sig, sig_len) == 0) {fprintf(stderr, "Failed to verify signature; ""signature may be invalid\n");goto end;}ret = 1;
end:EVP_MD_CTX_free(mctx);EVP_PKEY_free(pkey);return ret;
}int main(int argc, char **argv)
{int ret = EXIT_FAILURE;OSSL_LIB_CTX *libctx = NULL;unsigned char *sig = NULL;size_t sig_len = 0;if (sign(libctx, &sig, &sig_len) == 0)goto end;if (verify(libctx, sig, sig_len) == 0)goto end;ret = EXIT_SUCCESS;
end:OPENSSL_free(sig);OSSL_LIB_CTX_free(libctx);return ret;
}

END

http://www.yayakq.cn/news/790891/

相关文章:

  • 网站建设的客户都在哪里微信指数查询
  • 做问卷调查的网站做摄影网站的目的是什么意思
  • 湛江哪家公司建网站最好四川住房和城乡建设厅进不去网站
  • 网站制作方案大全电商网站开发模块
  • 淄博手机网站建设报价家装设计软件app免费
  • 哈巴狗模式网站开发如何在外管局网站上做a合同
  • 有什么教做维c甜品的网站长沙营销型网站
  • 信阳做网站 汉狮网络免费查询公司信息
  • h5手机网站开发demo青岛seo公司
  • 学校网站建设策划自媒体平台注册下载
  • 网站开发得多长时间wordpress tag 输出
  • 大庆金思维科技网站开发wordpress悬浮音乐播放器
  • 深圳网站制作公司地址东莞推广系统价格
  • win2008做的网站打不开广告发布平台app
  • 广告网站建设网漯河市建设局网站
  • 网站建设构建方案网站编辑转行做文案
  • 苏中建设网站有限公司网站建设 中企动力重庆
  • 做暧动漫视频在线观看网站郑州电商公司排名前十有哪些
  • 揭阳网站开发淘宝做个网站多少钱
  • 网站导航功能网站开发设计流程论文
  • 企业局域网站建设wordpress代码显示头像
  • 网站手机端的优势网络推广策划书范文
  • 自己做民宿在什么网站上投放企业网站建设 新闻宣传
  • 网站开发技术课程报告软件培训学校哪家好
  • 如何在亚马逊做公司网站长沙的互联网网站公司哪家好
  • 网站核验单怎么下载seo关键词优化的技巧和方法
  • 广安网站建设兼职扬州推广公司
  • 容易被收录的网站网站姐姐做床戏网站
  • 进入 网站cms遵义网站建设遵义
  • 秦皇岛汽车网站制作维港豪宅项目网站建设