#生成key openssl genrsa -aes256 -out root.key 4096 #生成csr openssl req -new -key root.key -out root.csr -subj "/C=US/O=test organization/OU=www.test.com/CN=test CA" #生成v3证书需要特殊的配置文件 openssl x509 -req -days 10950 -sha256 -extfile "D:\v3.cnf" -extensions v3_ca -extensions v3_req -signkey root.key -in root.csr -out root.crt #-name是友好名称 openssl pkcs12 -export -name "test CA" -out root.pfx -inkey root.key -in root.crt #从pfx中分离出cer openssl pkcs12 -nodes -nokeys -in root.pfx -passin pass:openssl -out root.cer(更多…)
-
openssl生成根证书
-
SYSTEM AppData Local目录
在SYSTEM SERVICE中获取到的APPDATA目录是
C:\Windows\system32\config\systemprofile\AppData\Local测试了Win7 64bit、Server 2019,均是如此。
(更多…)
-
linux/container_of.h 获得结构体指针
/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _LINUX_CONTAINER_OF_H #define _LINUX_CONTAINER_OF_H #include <linux/build_bug.h> #include <linux/err.h> #define typeof_member(T, m) typeof(((T*)0)->m) /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. * @type: the type of the container struct this is embedded in. * @member: the name of the member within the struct. * * WARNING: any const qualifier of @ptr is lost. */ #define container_of(ptr, type, member) ({ \ void *__mptr = (void *)(ptr); \ static_assert(__same_type(*(ptr), ((type *)0)->member) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); }) /** * container_of_const - cast a member of a structure out to the containing * structure and preserve the const-ness of the pointer * @ptr: the pointer to the member * @type: the type of the container struct this is embedded in. * @member: the name of the member within the struct. */ #define container_of_const(ptr, type, member) \ _Generic(ptr, \ const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\ default: ((type *)container_of(ptr, type, member)) \ ) #endif /* _LINUX_CONTAINER_OF_H */
-
openssl和Windows crypt32 AES加解密互通
// 在使用openssl加密时,为了让Windows crypt32 // API能很方便的解密,需要同步CryptDeriveKey的功能。 // 适用于win api端CryptCreateHash指定为CALG_MD5的情况。 // https://learn.microsoft.com/zh-cn/windows/win32/api/wincrypt/nf-wincrypt-cryptderivekey?redirectedfrom=MSDN unsigned char *crypt32DerivedKey(unsigned char *md5hash, int k /*hash长度*/, int keyBitSize) { /**step 1*/ unsigned char buffer1[64]; for (int i = 0; i < 64; i++) { buffer1[i] = 0x36; } // int k = n; for (int i = 0; i < k; i++) { buffer1[i] = buffer1[i] ^ md5hash[i]; } /*step 2*/ unsigned char buffer2[64]; for (int i = 0; i < 64; i++) { buffer2[i] = 0x5C; } for (int i = 0; i < k; i++) { buffer2[i] = buffer2[i] ^ md5hash[i]; } /*step 3*/ unsigned char hash1[MD5_DIGEST_LENGTH]; MD5(buffer1, 64, hash1); /*step 4*/ unsigned char hash2[MD5_DIGEST_LENGTH]; MD5(buffer2, 64, hash2); /*step 5*/ int resultLen = keyBitSize / 8; unsigned char *outputkey = (unsigned char *)malloc(resultLen); for (int i = 0; i < resultLen; i++) { if (i < 16) outputkey[i] = hash1[i]; else outputkey[i] = hash2[i - 16]; } return outputkey; }


