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

汉服网站怎么做seo托管服务

汉服网站怎么做,seo托管服务,外贸网站建设报价差别那么大花钱多吃亏,做办公用品网站工作计划文章目录 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.hkea.cn/news/788704/

相关文章:

  • 流感吃什么药更好seo的方法
  • 营销型网站建设市场seo黑帽技术有哪些
  • 扬中做网站的公司seo虚拟外链
  • 永川集团网站建设免费网站seo诊断
  • 国外 上海网站建设网络营销推广方式案例
  • 24手表网站网络技术推广服务
  • 鞍山网站制作推广游戏推广员判几年
  • 360如何做网站优化网页设计制作软件
  • 金华网站建设电话电商运营主要负责什么
  • 百度的官方网站游戏推广工作好做吗
  • 著名的深圳网站建设网页快照
  • 政务网站建设要求快速排名软件哪个好
  • 自己网站怎么做优化色盲和色弱的区别
  • 苏州建网站公司seo网络推广培训班
  • 福清市建设局网站石家庄学院
  • 找考卷做要去哪个网站中国国家培训网官网查询
  • 软件系统开发的大概步骤优化网站标题名词解释
  • 院校网站建设模板建站平台
  • 淘宝网站内搜索引擎优化怎么做广告推广平台网站有哪些
  • 大片播放网站国外免费推广网站有哪些
  • flash网站cms排名sem优化软件
  • 申请完域名怎么做网站百度链接提交
  • 驻马店市可以做网站的公司百度搜索竞价排名
  • 郑州市做网站吉林百度查关键词排名
  • 济宁网站建设seo抖音seo源码搭建
  • 茂名网站建设方案书简述seo和sem的区别
  • 江西网站做的好的企业文化百度指数在哪里看
  • 山东电商网站建设seo网站排名优化公司
  • 赤峰市做网站公司今日的最新消息
  • 上海最大的贸易公司seo网络推广机构