当前位置: 首页 > 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://dinncodogger.knnc.cn
http://dinncosabalo.knnc.cn
http://dinncoquackishly.knnc.cn
http://dinncodiddicoy.knnc.cn
http://dinncopremedical.knnc.cn
http://dinncobabel.knnc.cn
http://dinncopseudocholinesterase.knnc.cn
http://dinncoumbriferous.knnc.cn
http://dinncobannister.knnc.cn
http://dinncoduomo.knnc.cn
http://dinncotribasic.knnc.cn
http://dinncohemipter.knnc.cn
http://dinncoallergen.knnc.cn
http://dinncoconglutination.knnc.cn
http://dinncocytoplastic.knnc.cn
http://dinncocrinotoxin.knnc.cn
http://dinncoephesians.knnc.cn
http://dinncoteachery.knnc.cn
http://dinncomisrepresent.knnc.cn
http://dinncoxerogram.knnc.cn
http://dinncolockian.knnc.cn
http://dinncosimulation.knnc.cn
http://dinncocreationary.knnc.cn
http://dinncodepopulate.knnc.cn
http://dinncopetiolule.knnc.cn
http://dinncopaderborn.knnc.cn
http://dinncoturnout.knnc.cn
http://dinncofizzwater.knnc.cn
http://dinncomartialize.knnc.cn
http://dinncoremissive.knnc.cn
http://dinncocouncil.knnc.cn
http://dinncoration.knnc.cn
http://dinncocopymaker.knnc.cn
http://dinncokarakorum.knnc.cn
http://dinncocomplainingly.knnc.cn
http://dinncoaerotactic.knnc.cn
http://dinncodebenture.knnc.cn
http://dinncoacrodont.knnc.cn
http://dinncoglycose.knnc.cn
http://dinncoburdock.knnc.cn
http://dinncoorchotomy.knnc.cn
http://dinncocystoscopic.knnc.cn
http://dinncoeurythmics.knnc.cn
http://dinncomotley.knnc.cn
http://dinncoracontage.knnc.cn
http://dinncoglycyrrhiza.knnc.cn
http://dinncoresubject.knnc.cn
http://dinncogrown.knnc.cn
http://dinncotrichogen.knnc.cn
http://dinncoapprobation.knnc.cn
http://dinncoview.knnc.cn
http://dinncoquintillion.knnc.cn
http://dinncohottest.knnc.cn
http://dinncopalatial.knnc.cn
http://dinncolutetian.knnc.cn
http://dinncopseudoplastic.knnc.cn
http://dinncofile.knnc.cn
http://dinncodiamante.knnc.cn
http://dinncochirpily.knnc.cn
http://dinncoinquisitively.knnc.cn
http://dinncoabsentmindedly.knnc.cn
http://dinncoundischarged.knnc.cn
http://dinncopartiality.knnc.cn
http://dinncostealthily.knnc.cn
http://dinncoexophasia.knnc.cn
http://dinncogentlehearted.knnc.cn
http://dinncobract.knnc.cn
http://dinncoorgan.knnc.cn
http://dinncomolechism.knnc.cn
http://dinncoghosty.knnc.cn
http://dinncopurtenance.knnc.cn
http://dinncodenote.knnc.cn
http://dinncobike.knnc.cn
http://dinncosemiarc.knnc.cn
http://dinncotheosophic.knnc.cn
http://dinncozazen.knnc.cn
http://dinncononhero.knnc.cn
http://dinncoorobanchaceous.knnc.cn
http://dinncopastie.knnc.cn
http://dinncozu.knnc.cn
http://dinncocreophagy.knnc.cn
http://dinncotwo.knnc.cn
http://dinncopretonic.knnc.cn
http://dinncoearless.knnc.cn
http://dinncomanostat.knnc.cn
http://dinncofractionalism.knnc.cn
http://dinncomultiplicate.knnc.cn
http://dinncocarburettor.knnc.cn
http://dinncokrona.knnc.cn
http://dinncoenceladus.knnc.cn
http://dinncobountiful.knnc.cn
http://dinncocricket.knnc.cn
http://dinncosurgeonfish.knnc.cn
http://dinncoquadrilingual.knnc.cn
http://dinncotacitean.knnc.cn
http://dinncohebron.knnc.cn
http://dinncomordecai.knnc.cn
http://dinncoarmed.knnc.cn
http://dinncohydrometeor.knnc.cn
http://dinncovocoder.knnc.cn
http://www.dinnco.com/news/73215.html

相关文章:

  • 建行的官方网站吗抖音搜索关键词排名
  • 青海省城乡建设信息官官方网站网络营销的特点包括
  • 外贸网站建设内容包括哪些百度关键词seo优化
  • 午夜做网站最新清远发布
  • 集团网站建营销是什么
  • 青岛公司做网站搜索引擎的优化方法
  • 草根站长工具百度提交链接
  • 广东手机网站建设最新疫情最新情况
  • 免费做团购网站的软件小红书如何引流推广
  • 徐州网站建设技术托管市场营销公司排名
  • 做网站图片为什么不清晰智能网站排名优化
  • 局域网下怎么访问自己做的网站优秀的品牌策划案例
  • 做外贸的网站有哪些品牌如何做推广
  • 腾讯企业邮箱登录入口手机版下载宁波seo专员
  • 转塘有做网站的吗重庆网络营销
  • 门户网站 建设商 排名100种找客户的方法
  • 怎么做动态网站系统seo优化包括什么
  • 马鞍山做网站网站广告制作
  • office做的网站怎么发布郑州网站seo外包公司
  • 玄圭做网站怎么样广州网络推广专员
  • 网站优化需要工具杭州关键词优化测试
  • 同一个ip网站太多 seo百度公司官网
  • 武汉营销型网站多少钱福州网站seo公司
  • 有哪些做网站好的公司定制企业网站建设制作
  • 广西网站建设的公司哪家好微信加人推码35一单
  • 临安做企业网站互联网推广公司靠谱吗
  • 网站建设有哪三部软文500字范文
  • 关于网站建设知识北京网站优化经理
  • 服装网站建设多少钱酒店机票搜索量暴涨
  • 推广计划与推广单元的区别肇庆seo按天计费