openssl AF_ALG引擎使用

cmd

AF_ALG是Linux提供的一种虚拟接口,用于访问内核中的加密算法。在Linux中,可以使用AF_ALG接口配合加密算法框架(Crypto API)来进行加密操作。

以下是一个使用AF_ALG和openssl进行加密操作的例子:

# 加密
openssl engine -t afalg -k afalg -c# 加载AF_ALG引擎
openssl engine afalg# 设置会话使用的加密算法和密钥
openssl ciphers -v 'aes-128-cbc'# 加密文件
openssl enc -engine afalg -aes-128-cbc -in input.txt -out output.txt -pass pass:YOUR_PASSWORD

在这个例子中,我们首先加载AF_ALG加密引擎。然后,我们设置会话使用的加密算法为AES-128-CBC。最后,我们使用openssl的enc命令进行加密操作,指定输入文件input.txt和输出文件output.txt,并使用密钥mysecretkey进行加密。

注意:在使用AF_ALG引擎之前,你需要确保系统中已经安装了libafalg-dev包,并且你的内核支持AF_ALG。

这只是一个基本的示例,实际使用时可能需要根据具体的加密算法和系统配置进行调整。

测试实例:(这是在101编译服务器环境上测试的)

der@somewhere:~/tmp/tmp$ openssl engine -t afalg -k afalg -c
engine: Cannot mix flags and engine names.
engine: Use -help for summary.
der@somewhere:~/tmp/tmp$ openssl engine -t afalg -k afalg
engine: Cannot mix flags and engine names.
engine: Use -help for summary.
der@somewhere:~/tmp/tmp$ openssl engine -t afalg
(afalg) AFALG engine support[ available ]
der@somewhere:~/tmp/tmp$ 
der@somewhere:~/tmp/tmp$ 
der@somewhere:~/tmp/tmp$ openssl engines
Invalid command 'engines'; type "help" for a list.
der@somewhere:~/tmp/tmp$ openssl engine
(rdrand) Intel RDRAND engine
(dynamic) Dynamic engine loading support
der@somewhere:~/tmp/tmp$ openssl engine afalg
(afalg) AFALG engine support
der@somewhere:~/tmp/tmp$ openssl ciphers -v 'aes-128-cbc'
TLS_AES_256_GCM_SHA384  TLSv1.3 Kx=any      Au=any  Enc=AESGCM(256) Mac=AEAD
TLS_CHACHA20_POLY1305_SHA256 TLSv1.3 Kx=any      Au=any  Enc=CHACHA20/POLY1305(256) Mac=AEAD
TLS_AES_128_GCM_SHA256  TLSv1.3 Kx=any      Au=any  Enc=AESGCM(128) Mac=AEAD
der@somewhere:~/tmp/tmp$
der@somewhere:~/tmp/tmp$ find /usr/lib -name "*afalg*"
/usr/lib/x86_64-linux-gnu/engines-1.1/afalg.so
der@somewhere:~/tmp/tmp$
der@somewhere:~/tmp/tmp$ openssl enc -engine afalg -aes-128-cbc -in info.txt -out output.txt
engine "afalg" set.
enter aes-128-cbc encryption password:
Verifying - enter aes-128-cbc encryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
der@somewhere:~/tmp/tmp$
der@somewhere:~/tmp/tmp$ 
der@somewhere:~/tmp/tmp$ openssl enc -d -engine afalg -aes-128-cbc -in output.txt -out dec.txt -pass pass:somepasswd
engine "afalg" set.
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
der@somewhere:~/tmp/tmp$ 
der@somewhere:~/tmp/tmp$ md5sum info.txt dec.txt 
c50829378ad3f6ad668b290ef8b17cc4  info.txt
c50829378ad3f6ad668b290ef8b17cc4  dec.txt
der@somewhere:~/tmp/tmp$

code

加载

int main() {int ret = 1;int type = 0;do{printf("please choose type: 0:exit 1:load_builtin, 2:init_crypto AFALG, 3:init_crypto DYNAMIC, 4:add_all_algorithms\n");(void)scanf(" %d",&type);switch(type){case 0:return 0;case 1:ENGINE_load_builtin_engines();break;case 2:OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL);break;case 3:OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL);break;case 4:OpenSSL_add_all_algorithms();break;}ENGINE *e = ENGINE_by_id("afalg");if (e == NULL) {printf("Can not load AFALG engine.\n");continue;}printf("Load AFALG engine OK.\n");int rc = ENGINE_init(e);if (rc == 0) {printf("Init AFALG engine fail.\n");ENGINE_free(e);continue;}printf("Init AFALG engine OK.\n");//now we can use afalg engine

第1种第3种可以加载,2,4种不行

使用

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/engine.h>// colors used in printf
#define COLOR_NONE "\033[m"
#define COLOR_RED "\033[0;32;31m"
#define COLOR_LIGHT_RED "\033[1;31m"
#define COLOR_YELLOW "\033[1;33m"
#define COLOR_GREEN "\033[0;32;32m"
#define COLOR_BLUE "\033[0;32;34m"
#define COLOR_PURPLE "\033[0;32;35m"// switch of printf
#if 1
#define PRINT(...) printf(__VA_ARGS__)
#else
#define PRINT(...)
#endif#if 0
#define PRINTSUCCESS(...) printf(__VA_ARGS__)
#else
#define PRINTSUCCESS(...)
#endif#if 1
#define PRINTFAIL(...) printf(__VA_ARGS__)
#else
#define PRINTFAIL(...)
#endif// macros related to break
#define FREE_NOTNULL(ptr, func_name) \{                                \if (ptr != NULL)             \{                            \func_name(ptr);          \ptr = NULL;              \}                            \}#define CALL_FUNC(ret, funSentence, errCase)                                                                     \{                                                                                                            \ret = funSentence;                                                                                       \if (errCase)                                                                                             \{                                                                                                        \PRINTFAIL(COLOR_RED "[%s][%d] " #funSentence " fail:" #errCase "\n" COLOR_NONE, __FILE__, __LINE__); \break;                                                                                               \}                                                                                                        \else                                                                                                     \{                                                                                                        \PRINTSUCCESS(COLOR_GREEN "[%s][%d] " #funSentence " success\n" COLOR_NONE, __FILE__, __LINE__);      \}                                                                                                        \}#define CALL_FUNC_WITHIOUTBREAK(ret, funSentence, errCase)                                                       \{                                                                                                            \ret = funSentence;                                                                                       \if (errCase)                                                                                             \{                                                                                                        \PRINTFAIL(COLOR_RED "[%s][%d] " #funSentence " fail:" #errCase "\n" COLOR_NONE, __FILE__, __LINE__); \}                                                                                                        \else                                                                                                     \{                                                                                                        \PRINTSUCCESS(COLOR_GREEN "[%s][%d] " #funSentence " success\n" COLOR_NONE, __FILE__, __LINE__);      \}                                                                                                        \}#define CALL_FUNC_NOTNULL(ret, funSentence) \CALL_FUNC(ret, funSentence, ret == NULL)#define CALL_FUNC_POSITIVE(ret, funSentence) \CALL_FUNC(ret, funSentence, ret <= 0)#define CALL_NBFUNC_NOTNULL(ret, funSentence) \CALL_FUNC_WITHIOUTBREAK(ret, funSentence, ret == NULL)#define CALL_NBFUNC_POSITIVE(ret, funSentence) \CALL_FUNC_WITHIOUTBREAK(ret, funSentence, ret <= 0)#define BUFFER_SIZE 256static void print_hex(const char *info, unsigned char *data, unsigned int len)
{printf("%s[len:%d | 0x%x]\n", info, len, len);for (int i = 0; i < len; i++){printf("%02x ", data[i]);}printf("\n");
}static int test_afalg_aes_cbc(ENGINE *engine)
{EVP_CIPHER_CTX *ctx = NULL;const EVP_CIPHER *cipher;unsigned char key[] = "\x06\xa9\x21\x40\x36\xb8\xa1\x5b""\x51\x2e\x03\xd5\x34\x12\x00\x06""\x06\xa9\x21\x40\x36\xb8\xa1\x5b""\x51\x2e\x03\xd5\x34\x12\x00\x06";unsigned char iv[] = "\x3d\xaf\xba\x42\x9d\x9e\xb4\x30""\xb4\x22\xda\x80\x2c\x9f\xac\x41";/* input = "Single block msg\n"  17Bytes*/unsigned char in[BUFFER_SIZE] = "\x53\x69\x6e\x67\x6c\x65\x20\x62""\x6c\x6f\x63\x6b\x20\x6d\x73\x67\x0a";unsigned char ebuf[BUFFER_SIZE + 32];unsigned char dbuf[BUFFER_SIZE + 32];unsigned char encresult_128[] = "\xe3\x53\x77\x9c\x10\x79\xae\xb8""\x27\x08\x94\x2d\xbe\x77\x18\x1a\x2d";unsigned char encresult_192[] = "\xf7\xe4\x26\xd1\xd5\x4f\x8f\x39""\xb1\x9e\xe0\xdf\x61\xb9\xc2\x55\xeb";unsigned char encresult_256[] = "\xa0\x76\x85\xfd\xc1\x65\x71\x9d""\xc7\xe9\x13\x6e\xae\x55\x49\xb4\x13";unsigned char *enc_result = NULL;int encl, encf, decl, decf;int ret = 0;int keysize_idx = 0;printf("please choose key len: 0:128, 1:192, 2:256 else:128\n");(void)scanf(" %d", &keysize_idx);do{switch (keysize_idx){case 0:cipher = EVP_aes_128_cbc();enc_result = &encresult_128[0];break;case 1:cipher = EVP_aes_192_cbc();enc_result = &encresult_192[0];break;case 2:cipher = EVP_aes_256_cbc();enc_result = &encresult_256[0];break;default:cipher = EVP_aes_128_cbc();enc_result = &encresult_128[0];break;}CALL_FUNC_NOTNULL(ctx, EVP_CIPHER_CTX_new())print_hex("src data", in, BUFFER_SIZE);CALL_FUNC_POSITIVE(ret, EVP_CipherInit_ex(ctx, cipher, engine, key, iv, 1))CALL_FUNC_POSITIVE(ret, EVP_CipherUpdate(ctx, ebuf, &encl, in, BUFFER_SIZE))CALL_FUNC_POSITIVE(ret, EVP_CipherFinal_ex(ctx, ebuf + encl, &encf))encl += encf;print_hex("enc data", ebuf, encl);// CALL_FUNC(ret,memcmp(enc_result, ebuf, BUFFER_SIZE),ret != 0)CALL_FUNC_POSITIVE(ret, EVP_CIPHER_CTX_reset(ctx))CALL_FUNC_POSITIVE(ret, EVP_CipherInit_ex(ctx, cipher, engine, key, iv, 0))CALL_FUNC_POSITIVE(ret, EVP_CipherUpdate(ctx, dbuf, &decl, ebuf, encl))CALL_FUNC_POSITIVE(ret, EVP_CipherFinal_ex(ctx, dbuf + decl, &decf))print_hex("dec data", dbuf, decl);decl += decf;CALL_FUNC_POSITIVE(ret, decl == BUFFER_SIZE)CALL_FUNC(ret, memcmp(dbuf, in, BUFFER_SIZE), ret != 0)printf("engine enc dec success.\n");ret = 1;} while (0);
end:FREE_NOTNULL(ctx, EVP_CIPHER_CTX_free)return ret;
}int test_engine_digest(ENGINE *engine)
{int ret = 0;const EVP_MD *md = NULL;EVP_MD_CTX *emctx = NULL;unsigned char data[128] = {1, 2, 4};unsigned char digestData[64] = {0};unsigned int digestSize = sizeof(digestData);const char *eName = NULL;do{CALL_FUNC_NOTNULL(eName, ENGINE_get_name(engine))printf("engine name:%s\n", eName);CALL_FUNC_POSITIVE(ret, ENGINE_register_digests(engine))               //CALL_FUNC_POSITIVE(ret, ENGINE_set_default(engine, ENGINE_METHOD_ALL)) // ENGINE_METHOD_DIGESTS))CALL_FUNC_NOTNULL(emctx, EVP_MD_CTX_new())CALL_FUNC_POSITIVE(ret, EVP_MD_CTX_init(emctx))CALL_FUNC_NOTNULL(md, EVP_md5())digestSize = sizeof(digestData);CALL_FUNC_POSITIVE(ret, EVP_DigestInit_ex(emctx, md, engine))CALL_FUNC_POSITIVE(ret, EVP_DigestUpdate(emctx, data, sizeof(data)))CALL_FUNC_POSITIVE(ret, EVP_DigestFinal(emctx, digestData, &digestSize))print_hex("MD5 3 segment result", digestData, digestSize);memset(digestData, 0, sizeof(digestData));digestSize = sizeof(digestData);// CALL_FUNC_POSITIVE(ret,EVP_DigestInit_ex(emctx,md,engine))CALL_FUNC_POSITIVE(ret, EVP_Digest(data, sizeof(data), digestData, &digestSize, md, engine))print_hex("MD5 1 segment result", digestData, digestSize);memset(digestData, 0, sizeof(digestData));digestSize = sizeof(digestData);CALL_FUNC_NOTNULL(md, EVP_sha1())CALL_FUNC_POSITIVE(ret, EVP_DigestInit_ex(emctx, md, engine))CALL_FUNC_POSITIVE(ret, EVP_DigestUpdate(emctx, data, sizeof(data)))CALL_FUNC_POSITIVE(ret, EVP_DigestFinal(emctx, digestData, &digestSize))print_hex("SHA1 3 segment result", digestData, digestSize);memset(digestData, 0, sizeof(digestData));digestSize = sizeof(digestData);CALL_FUNC_NOTNULL(md, EVP_sha256())CALL_FUNC_POSITIVE(ret, EVP_DigestInit_ex(emctx, md, engine))CALL_FUNC_POSITIVE(ret, EVP_DigestUpdate(emctx, data, sizeof(data)))CALL_FUNC_POSITIVE(ret, EVP_DigestFinal(emctx, digestData, &digestSize))print_hex("SHA256 3 segment result", digestData, digestSize);} while (0);// FREE_NOTNULL(md,EVP_md5xx) //do not need freeFREE_NOTNULL(emctx, EVP_MD_CTX_free)return ret;
}int main()
{int ret = 1;int type = 0;do{printf("please choose type: 0:exit 1:load_builtin, 2:init_crypto AFALG, 3:init_crypto DYNAMIC, 4:add_all_algorithms\n");(void)scanf(" %d", &type);switch (type){case 0:return 0;case 1:ENGINE_load_builtin_engines();break;case 2:OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL);break;case 3:OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL);break;case 4:OpenSSL_add_all_algorithms();break;}ENGINE *e = ENGINE_by_id("afalg");if (e == NULL){printf("Can not load AFALG engine.\n");continue;}printf("Load AFALG engine OK.\n");int rc = ENGINE_init(e);if (rc == 0){printf("Init AFALG engine fail.\n");ENGINE_free(e);continue;}printf("Init AFALG engine OK.\n");// now we can use afalg engineCALL_FUNC_POSITIVE(ret, test_afalg_aes_cbc(e))CALL_FUNC_POSITIVE(ret, test_engine_digest(e))// ENGINE_free(e);ENGINE_finish(e);} while (type != 0);return 0;
}
der@somewhere:~/tmp/tmp/engine$ gcc -o engine engine.c -lcrypto
der@somewhere:~/tmp/tmp/engine$ ./engine 
please choose type: 0:exit 1:load_builtin, 2:init_crypto AFALG, 3:init_crypto DYNAMIC, 4:add_all_algorithms
3
Load AFALG engine OK.
Init AFALG engine OK.
please choose key len: 0:128, 1:192, 2:256 else:128
2
src data[len:256 | 0x100]
53 69 6e 67 6c 65 20 62 6c 6f 63 6b 20 6d 73 67 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
enc data[len:272 | 0x110]
a0 76 85 fd c1 65 71 9d c7 e9 13 6e ae 55 49 b4 ca 9f 86 f1 4f 52 d9 66 6c a1 f9 25 ae 42 c6 d9 e6 f2 15 3a 08 14 c2 e0 02 06 de e2 c1 45 ba 02 dc 36 85 a8 2e 74 a3 68 b8 96 69 0f 78 59 34 50 77 85 24 00 f1 54 ea 9f 75 b7 61 c1 db a1 ad b3 3b b5 c1 c9 77 9f f0 f8 fc 95 f1 36 17 34 c5 03 41 43 1e 6e 69 e8 e1 88 fb d1 ac 0c 46 6e 71 26 52 a3 91 b3 87 dc 6a 16 e4 02 a8 a4 8b 4c 6a c1 ef 5d 92 3b ab 43 cc 80 34 5a c6 52 c6 48 8b a0 f5 14 12 85 55 78 92 80 30 5f f9 45 e1 fe 61 e9 02 da a1 69 19 a1 92 16 87 f2 a3 8d e3 e8 15 34 69 c2 40 69 2b 15 43 27 da 4e 56 15 d3 10 e5 55 58 8c d0 0e ee 2b 3f 00 57 e8 65 7f ac d5 01 af 9a 13 1a c0 ae ac b1 a8 01 46 f7 15 2d 26 22 b1 87 a0 ee db a3 fb 9d a3 94 77 91 e1 72 25 5e 9c 17 d6 d6 5f e9 3c 2f 0f bb be 79 1f 99 06 7e 37 68 67 9c 76 04 dc de e3 dc ed dd c9 32 fd dc 7d 
dec data[len:256 | 0x100]
53 69 6e 67 6c 65 20 62 6c 6f 63 6b 20 6d 73 67 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
engine enc dec success.
engine name:AFALG engine support
[engine.c][197] EVP_DigestInit_ex(emctx,md,engine) fail:ret <= 0
[engine.c][271] test_engine_digest(e) fail:ret <= 0
der@somewhere:~/tmp/tmp/engine$ 
der@somewhere:~/tmp/tmp/engine$

可以看到aes使用afalg引擎成功,但是digest使用引擎失败了。之前好像看到过说明,digest软算法很快,如果使用硬件加速引擎综合开销反而更大或者效率提升不明显,如果需要引擎支持digest需要编译openssl的时候指定相应标志。就这样。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/289039.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

我的编程之路:从非计算机专业到Java开发工程师的成长之路 | 学习路线 | Java | 零基础 | 学习资源 | 自学

小伙伴们好&#xff0c;我是「 行走的程序喵」&#xff0c;感谢您阅读本文&#xff0c;欢迎三连~ &#x1f63b; 【Java基础】专栏&#xff0c;Java基础知识全面详解&#xff1a;&#x1f449;点击直达 &#x1f431; 【Mybatis框架】专栏&#xff0c;入门到基于XML的配置、以…

Win10或Win11系统下西门子TIA博途运行时卡顿缓慢的解决办法总结

Win10或Win11系统下西门子TIA博途运行时卡顿缓慢的解决办法总结 首先,可以看下TIA PORTAL V19的安装条件: 处理器:Intel i5-8400H,2.5-4.2GHZ,4核以上+超线程技术,智能缓存; 内存:至少16GB,大型项目需要32GB 硬盘:必须SSD固态硬盘,至少50GB的可用空间 图形分辨率:1…

PostgreSQL FDW(外部表) 简介

1、FDW: 外部表 背景 提供外部数据源的透明访问机制。PostgreSQL fdw(Foreign Data Wrapper)是一种外部访问接口,可以在PG数据库中创建外部表,用户访问的时候与访问本地表的方法一样,支持增删改查。 而数据则是存储在外部,外部可以是一个远程的pg数据库或者其他数据库(…

LVS负载均衡-DR模式配置

LVS&#xff1a;Linux virtual server ,即Linux虚拟服务器 LVS自身是一个负载均衡器&#xff08;Director&#xff09;&#xff0c;不直接处理请求&#xff0c;而是将请求转发至位于它后端的真实服务器real server上。 LVS是四层&#xff08;传输层 tcp/udp&#xff09;负载均衡…

数据结构——二叉搜索树详解

一、二叉搜索树定义 二叉搜索树又称二叉排序树&#xff0c;它或者是一棵空树&#xff0c;或者是具有以下性质的二叉树: 1.非空左子树上所有节点的值都小于根节点的值。 2.非空右子树上所有节点的值都大于根节点的值。 3.左右子树也都为二叉搜索树。 如下图所示&#xff1a…

振弦采集仪在预防地质灾害监测中的作用与应用前景

振弦采集仪在预防地质灾害监测中的作用与应用前景 振弦采集仪&#xff08;String Vibrating Sensor&#xff0c;简称SVM&#xff09;是一种用于地质灾害监测的重要仪器&#xff0c;它通过测量地面振动信号来预测和预警地质灾害的发生。SVM的作用在于提供实时、准确的地质灾害监…

vue3+ts+element home页面侧边栏+头部组件+路由组件组合页面教程

文章目录 效果展示template代码script代码样式代码 效果展示 template代码 <template><el-container class"home"><el-aside class"flex" :style"{ width: asideDisplay ? 70px : 290px }"><div class"aside-left&q…

深度学习语义分割篇——DeepLabV1原理详解篇

&#x1f34a;作者简介&#xff1a;秃头小苏&#xff0c;致力于用最通俗的语言描述问题 &#x1f34a;专栏推荐&#xff1a;深度学习网络原理与实战 &#x1f34a;近期目标&#xff1a;写好专栏的每一篇文章 &#x1f34a;支持小苏&#xff1a;点赞&#x1f44d;&#x1f3fc;、…

数据库是怎么做到事务回滚的呢?

数据库实现事务回滚的原理涉及到数据库管理系统&#xff08;DBMS&#xff09;如何维护事务的一致性和持久性。 基本原理&#xff1a; ACID属性&#xff1a;事务的原子性&#xff08;Atomicity&#xff09;、一致性&#xff08;Consistency&#xff09;、隔离性&#xff08;Iso…

【Linux】从零开始认识进程 — 中下篇

送给大家一句话&#xff1a; 人一切的痛苦&#xff0c;本质上都是对自己无能的愤怒。而自律&#xff0c;恰恰是解决人生痛苦的根本途径。—— 王小波 从零认识进程 1 进程优先级1.1 什么是优先级1.2 为什么要有优先级1.3 Linux优先级的特点 && 查看方式1.4 其他概念 2…

c++的学习之路:5、类和对象(1)

一、面向对象和面向过程 在说这个定义时&#xff0c;我就拿c语言举例&#xff0c;在c语言写程序的时候&#xff0c;基本上就是缺什么函数&#xff0c;就去手搓一个函数&#xff0c;写的程序也只是调用函数的&#xff0c;而c就是基于面向对象的开发&#xff0c;他关注的不再是单…

picgo启动失败解决

文章目录 报错信息原因分析解决方案 报错信息 打开Picgo&#xff0c;显示报错 A JavaScript error occurred in the main process Uncaught Exception: Error:ENOENT:no such file or directory,open ‘C:\Users\koko\AppData\Roaming\picgo\data.json\picgo.log’ 原因分析…

[iOS]GCD(一)

[iOS]GCD(一) 文章目录 [iOS]GCD(一)GCD的概要GCD的APIDispatch Queuedispatch_queue_createMain Dispatch Queue和 Global Dispatch Queue.Main Dispatch_set_target_queuedispatch_afterDispatch Groupdispatch_barrier_asyncdispatch_applydispatch_applydispatch_suspend/d…

【功能实现】新年贺卡(蓝桥)

题目分析&#xff1a; 想要实现一个随机抽取功能 功能拆解&#xff1a;题目给了数组&#xff0c;我们采用生成随机数的方式&#xff0c;随机数作为数组的索引值访问数组的值。 并返回获取到的值&#xff0c;将获取到的值插入到页面中。 document.addEventListener(DOMConten…

哪款软件适合做书单的背景图片?安利这3款

哪款软件适合做书单的背景图片&#xff1f;在数字化时代&#xff0c;书单作为推广阅读文化、分享书籍信息的重要载体&#xff0c;其视觉效果与内容的吸引力同等重要。一个精美的书单背景图片&#xff0c;不仅能够吸引读者的眼球&#xff0c;还能增强书单的传播效果。因此&#…

Redis 教程系列之Redis 集群配置(十三)

1.Redis集群方案比较 主从模式 在软件的架构中,主从模式(Master-Slave)是使用较多的一种架构。主(Master)和从(Slave)分别部署在不同的服务器上,当主节点服务器写入数据时,同时也会将数据同步至从节点服务器,通常情况下,主节点负责写入数据,而从节点负责读取数据。…

Java I/O

什么是 IO流&#xff1f; 存储和读取数据的解决方案 I: input O: output 流&#xff1a;像水流一样传输数据 IO流的作用&#xff1f; 用于读写数据&#xff08;本地文件&#xff0c;网络&#xff09; IO流从 传输方式 分类 字符是给人看的&#xff0c;字节是给计算机看的。 …

八、C#计数排序算法

简介 计数排序是一种非比较性的排序算法&#xff0c;适用于排序一定范围内的整数。它的基本思想是通过统计每个元素的出现次数&#xff0c;然后根据元素的大小依次输出排序结果。 实现原理 首先找出待排序数组中的最大值max和最小值min。 创建一个长度为max-min1的数组count…

Java:反射 reflection ( 概念+相关类+使用方法)

文章目录 一、反射(reflection)1.概念优点&#xff1a;缺点 2.反射的相关类1.Class类1.**反射机制的起源**2.获得类相关的方法3.获得类中属性的相关方法4.获得类中注解相关的方法5.获得类中构造器相关的方法6.获得类中方法相关的方法 2.获取Class对象的三种方法&#xff1a;1.使…

【算法刷题】链表笔试题解析(1)

一、链表分割 题目描述&#xff1a; 链接&#xff1a;链表分割 题目分析&#xff1a; 这题直接处理并不好做&#xff0c;我们可以构建前后两个链表&#xff0c;将小于x值的结点放在链表a内&#xff0c;将其它结点放在链表b内&#xff0c;这样将原链表遍历完后&#xff0c;原链…