📄 readpk.c
字号:
#include <unistd.h> #include <stdlib.h> #include <fcntl.h>#include <sys/ioctl.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <openssl/pem.h>#include <openssl/conf.h>#include <openssl/x509v3.h>#include <openssl/engine.h>/*static intkey_perm_ok(int fd, const char *filename){struct stat st;if (fstat(fd, &st) < 0)return 0;if ((st.st_uid == getuid()) && (st.st_mode & 077) != 0) {error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");error("@ WARNING: UNPROTECTED PRIVATE KEY FILE! @");error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");error("Permissions 0%3.3o for '%s' are too open.",(u_int)st.st_mode & 0777, filename);error("It is recommended that your private key files are NOT accessible by others.");error("This private key will be ignored.");return 0;}return 1;}*/void key_load_private_pem(char * file, const char *passphrase,char **commentp){FILE *fp;EVP_PKEY *pk = NULL;char *name = "";fp = fopen(file, "r");if (fp == NULL) {error("fdopen failed: %s", strerror(errno));return ;}printf("%s",passphrase);pk = PEM_read_PrivateKey(fp, NULL, NULL, (char *)passphrase);if (pk == NULL) {printf("PEM_read_PrivateKey failed");}}void key_load_private(const char *filename, const char *passphrase,char **commentp){EVP_PKEY *pk;//lseek(fd, (off_t) 0, SEEK_SET); /* rewind *//* closes fd */ key_load_private_pem(filename, passphrase, NULL);}int main(){ key_load_private("ca.key","jianglei",NULL);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -