dhdhy.cpp

来自「X.509de yingyong 和开发的.具体可以先学习一下.openssl的」· C++ 代码 · 共 44 行

CPP
44
字号
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <errno.h>
#include <sys/types.h>

#include <winsock2.h>

#include "openssl/rsa.h"
#include "openssl/crypto.h"
#include "openssl/x509.h"
#include "openssl/pem.h"
#include "openssl/ssl.h"
#include "openssl/err.h"
#include "openssl/rand.h"


int	main()
	{
		X509			*x;
		FILE			*fp;
		unsigned char	buf[5000],*p;
		int				len,ret;
		BIO				*b;
	
		/* cert.cer为DER编码的数字证书 
用户如果是windows系统,可以从IE中导出一个x509v3的数字证书作为解析目标
*/
		fp=fopen("cert.cer","rb");
		if(!fp) return -1;
		len=fread(buf,1,5000,fp);
		fclose(fp);
	
		p=buf;
		x=X509_new();
		d2i_X509(&x,(unsigned char **)&p,len);
		b=BIO_new(BIO_s_file());
		BIO_set_fp(b,stdout,BIO_NOCLOSE);
		ret=X509_print(b,x);
		BIO_free(b);
		X509_free(x);
		return 0;
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?