Unity中數據和資源加密(異或加密,AES加密,MD5加密)

在項目開發中,始終會涉及到的一個問題,就是信息安全,在調用接口,或者加載的資源,都會涉及安全問題,因此就出現了各種各樣的加密方式。

常見的也是目前用的最廣的加密方式,分別是:DES、3DES、AES、MD5、XOR(異或)

其中DES、3DES、AES、MD5用在數據加密中偏多,特別是接口調用數據信息傳輸上。

XOR異或加密用在資源加密上偏多。

因此很多工程師會整理一個通用的加密工具類,因此我這邊也同樣整理了一個工具腳本。

但DES和3DES之前項目中沒用到過,因此還沒整理,等后續如果有碰到會再更新。

下面主要是AES、MD5、XOR加密方式

1、XOR(異或加密)

異或加密其實很簡單,就是將二進制明文數據進行異或運算,解密時,只需要對密文再次異或運算即可。異或運算原理是,相同為 0,不同為 1

因此加密代碼和解密代碼一致,但是根據密鑰可以是 單個byte,或者 多個byte,這就導致出現了,更復雜的加密方式,例如對明文數據索引的取余等等。當索引滿足什么條件時進行加密,不滿足時不進行加密。

例如下方代碼

/// <summary>
/// 異或操作
/// </summary>
/// <param name="data"></param>
/// <param name="key"></param>
/// <returns></returns>
public static byte[] XorCipher(byte[] data, byte key = XorDefaultPassword)
{for (int i = 0; i < data.Length; i++){data[i] ^= key;}return data;
}/// <summary>
/// 異或操作
/// </summary>
/// <param name="data"> 數據 </param>
/// <param name="key"> 密鑰 </param>
/// <param name="isRemainder"> 是否取余(數據索引,對key長度取余,不等于0時加密) </param>
/// <returns></returns>
public static byte[] XorCipher(byte[] data, byte[] key=null,bool isRemainder = true)
{if (key == null || key.Length <= 0) key = XorArrayPassword;for (int i = 0; i < data.Length; i++){if (!isRemainder){data[i] ^= key[i % key.Length];}else{if (i % key.Length != 0){data[i] ^= key[i % key.Length];}}}return data;
}

2、MD5加密

MD5碼是個很常見的東西,特別是在做資源熱更新的,很多公司會對給資源文件一個MD5編碼,用作版本管理,判斷這個編碼是否一致,一致就不更新,不一致就更新資源。但這個編碼的計算方式也可以用來做數據的加密。

        /// <summary> /// 加密數據 /// </summary> /// <param name="content"></param> /// <param name="key"></param> /// <returns></returns> public static string EncryptByMD5(string content, string key = DefaultPassword){var des = System.Security.Cryptography.DES.Create();byte[] inputByteArray;inputByteArray = System.Text.Encoding.Default.GetBytes(content);System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();des.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(System.BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.Default.GetBytes(key + "md5"))).Replace("-", null).Substring(0, 8));des.IV = System.Text.ASCIIEncoding.ASCII.GetBytes(System.BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.Default.GetBytes(key + "md5"))).Replace("-", null).Substring(0, 8));System.IO.MemoryStream ms = new System.IO.MemoryStream();System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);cs.Write(inputByteArray, 0, inputByteArray.Length);cs.FlushFinalBlock();System.Text.StringBuilder ret = new System.Text.StringBuilder();foreach (byte b in ms.ToArray()){ret.AppendFormat("{0:X2}", b);}return ret.ToString();}/// <summary> /// 解密數據 /// </summary> /// <param name="content"></param> /// <param name="key"></param> /// <returns></returns> public static string DecryptByMD5(string content, string key = DefaultPassword){var des = System.Security.Cryptography.DES.Create();int len;len = content.Length / 2;byte[] inputByteArray = new byte[len];int x, i;for (x = 0; x < len; x++){i = System.Convert.ToInt32(content.Substring(x * 2, 2), 16);inputByteArray[x] = (byte)i;}System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();des.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(System.BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(key + "md5"))).Replace("-", null).Substring(0, 8));des.IV = System.Text.ASCIIEncoding.ASCII.GetBytes(System.BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(key + "md5"))).Replace("-", null).Substring(0, 8));System.IO.MemoryStream ms = new System.IO.MemoryStream();System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);cs.Write(inputByteArray, 0, inputByteArray.Length);cs.FlushFinalBlock();return System.Text.Encoding.Default.GetString(ms.ToArray());}

3、AES加密

一度是目前實用最廣泛的加密方式,雖然也被發現了破解方式,但安全性以及效率都還是比較高的加密方式,因此還在被廣泛的使用中。

提供了幾種方法:
1、字符串加密后返回字符串
2、字符串加密后返回字節數組
3、字節數組加密后返回字符串
4、字節數組加密后返回字節數組

   /// <summary>/// AES加密/// </summary>/// <param name="content"> 原文 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字節數組 </returns>public static byte[] EncryptToBytesByAes(string content, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);byte[] encrypted;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create an encryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform encryptor = aesAlg.CreateEncryptor();// Create the streams used for encryption.using (System.IO.MemoryStream msEncrypt = new System.IO.MemoryStream()){using (System.Security.Cryptography.CryptoStream csEncrypt = new System.Security.Cryptography.CryptoStream(msEncrypt, encryptor, System.Security.Cryptography.CryptoStreamMode.Write)){using (System.IO.StreamWriter swEncrypt = new System.IO.StreamWriter(csEncrypt)){//Write all data to the stream.swEncrypt.Write(content);}encrypted = msEncrypt.ToArray();}}}// Return the encrypted bytes from the memory stream.return encrypted;}/// <summary>/// AES加密/// </summary>/// <param name="content"> 原文 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字節數組 </returns>public static byte[] EncryptToBytesByAes(byte[] content, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);byte[] encrypted;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create an encryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform encryptor = aesAlg.CreateEncryptor();// Create the streams used for encryption.using (System.IO.MemoryStream msEncrypt = new System.IO.MemoryStream()){using (System.Security.Cryptography.CryptoStream csEncrypt = new System.Security.Cryptography.CryptoStream(msEncrypt, encryptor, System.Security.Cryptography.CryptoStreamMode.Write)){using (System.IO.StreamWriter swEncrypt = new System.IO.StreamWriter(csEncrypt)){//Write all data to the stream.swEncrypt.Write(content);}encrypted = msEncrypt.ToArray();}}}// Return the encrypted bytes from the memory stream.return encrypted;}/// <summary>/// AES加密/// </summary>/// <param name="content"> 原文 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字符串 </returns>public static string EncryptToStringByAes(string content, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);byte[] encrypted;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create an encryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform encryptor = aesAlg.CreateEncryptor();// Create the streams used for encryption.using (System.IO.MemoryStream msEncrypt = new System.IO.MemoryStream()){using (System.Security.Cryptography.CryptoStream csEncrypt = new System.Security.Cryptography.CryptoStream(msEncrypt, encryptor, System.Security.Cryptography.CryptoStreamMode.Write)){using (System.IO.StreamWriter swEncrypt = new System.IO.StreamWriter(csEncrypt)){//Write all data to the stream.swEncrypt.Write(content);}encrypted = msEncrypt.ToArray();}}}// Return the encrypted bytes from the memory stream.return System.Text.Encoding.Default.GetString(encrypted);}/// <summary>/// AES加密/// </summary>/// <param name="content"> 原文 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字符串 </returns>public static string EncryptToStringByAes(byte[] content, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);byte[] encrypted;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create an encryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform encryptor = aesAlg.CreateEncryptor();// Create the streams used for encryption.using (System.IO.MemoryStream msEncrypt = new System.IO.MemoryStream()){using (System.Security.Cryptography.CryptoStream csEncrypt = new System.Security.Cryptography.CryptoStream(msEncrypt, encryptor, System.Security.Cryptography.CryptoStreamMode.Write)){using (System.IO.StreamWriter swEncrypt = new System.IO.StreamWriter(csEncrypt)){//Write all data to the stream.swEncrypt.Write(content);}encrypted = msEncrypt.ToArray();}}}// Return the encrypted bytes from the memory stream.return System.Text.Encoding.Default.GetString(encrypted);}/// <summary>/// AES解密/// </summary>/// <param name="content"> 加密數據 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字節數組 </returns>public static byte[] DecryptToBytesByAes(byte[] data, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);// the decrypted text.byte[] content;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create a decryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform decryptor = aesAlg.CreateDecryptor();// Create the streams used for decryption.using (System.IO.MemoryStream msDecrypt = new System.IO.MemoryStream(data)){using (System.Security.Cryptography.CryptoStream csDecrypt = new System.Security.Cryptography.CryptoStream(msDecrypt, decryptor, System.Security.Cryptography.CryptoStreamMode.Read)){using (System.IO.StreamReader srDecrypt = new System.IO.StreamReader(csDecrypt)){// Read the decrypted bytes from the decrypting stream// and place them in a string.var Text = srDecrypt.ReadToEnd();content = System.Text.Encoding.Default.GetBytes(Text);}}}}return content;}/// <summary>/// AES解密/// </summary>/// <param name="content"> 加密數據 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字節數組 </returns>public static byte[] DecryptToBytesByAes(string data, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);// the decrypted text.byte[] content;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create a decryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform decryptor = aesAlg.CreateDecryptor();// Create the streams used for decryption.using (System.IO.MemoryStream msDecrypt = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(data))){using (System.Security.Cryptography.CryptoStream csDecrypt = new System.Security.Cryptography.CryptoStream(msDecrypt, decryptor, System.Security.Cryptography.CryptoStreamMode.Read)){using (System.IO.StreamReader srDecrypt = new System.IO.StreamReader(csDecrypt)){// Read the decrypted bytes from the decrypting stream// and place them in a string.var Text = srDecrypt.ReadToEnd();content = System.Text.Encoding.Default.GetBytes(Text);}}}}return content;}/// <summary>/// AES解密/// </summary>/// <param name="content"> 加密數據 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字符串 </returns>public static string DecryptToStringByAes(byte[] data, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);// the decrypted text.string content = string.Empty;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create a decryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform decryptor = aesAlg.CreateDecryptor();// Create the streams used for decryption.using (System.IO.MemoryStream msDecrypt = new System.IO.MemoryStream(data)){using (System.Security.Cryptography.CryptoStream csDecrypt = new System.Security.Cryptography.CryptoStream(msDecrypt, decryptor, System.Security.Cryptography.CryptoStreamMode.Read)){using (System.IO.StreamReader srDecrypt = new System.IO.StreamReader(csDecrypt)){// Read the decrypted bytes from the decrypting stream// and place them in a string.content = srDecrypt.ReadToEnd();}}}}return content;}/// <summary>/// AES解密/// </summary>/// <param name="content"> 加密數據 </param>/// <param name="password"> 密鑰 </param>/// <returns> 字節數組 </returns>public static string DecryptToStringByAes(string data, string key = DefaultPassword, string iv = DefaultPassword){var keyData = System.Text.Encoding.Default.GetBytes(key);var ivData = System.Text.Encoding.Default.GetBytes(iv);// the decrypted text.string content = string.Empty;// Create an Aes object// with the specified key and IV.using (System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create()){aesAlg.Key = keyData;aesAlg.IV = ivData;aesAlg.Mode = System.Security.Cryptography.CipherMode.CBC;aesAlg.Padding = System.Security.Cryptography.PaddingMode.ISO10126;// Create a decryptor to perform the stream transform.System.Security.Cryptography.ICryptoTransform decryptor = aesAlg.CreateDecryptor();// Create the streams used for decryption.using (System.IO.MemoryStream msDecrypt = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(data))){using (System.Security.Cryptography.CryptoStream csDecrypt = new System.Security.Cryptography.CryptoStream(msDecrypt, decryptor, System.Security.Cryptography.CryptoStreamMode.Read)){using (System.IO.StreamReader srDecrypt = new System.IO.StreamReader(csDecrypt)){// Read the decrypted bytes from the decrypting stream// and place them in a string.content = srDecrypt.ReadToEnd();}}}}return content;}

目前整理的就這幾種,之后如果有更新,再更新添加過來。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/80475.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/80475.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/80475.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

部署本地deepseek并在調用的詳細步驟以及解決一些可能出現的問題(Windows,Linux, WSL)

打開Ollama官網&#xff1a;https://ollama.com/ 直接下載Ollama并且安裝好Ollama、這時候就能看到app里多了個ollama&#xff0c;但是我們不用打開它 打開Windows Powershell&#xff1a; ollama run deepseek-r1:1.5b 7b 8b 14b 32b 70b 根據自己的電腦配置和需求更換不同的…

【KWDB 創作者計劃】_嵌入式硬件篇---寄存器與存儲器截斷與溢出

文章目錄 前言一、寄存器與存儲器1. 定義與基本概念寄存器(Register)位置功能特點存儲器(Memory)位置功能特點2. 關鍵區別3. 層級關系與協作存儲層次結構協作示例4. 為什么需要寄存器性能優化指令支持減少總線競爭5. 其他寄存器類型專用寄存器程序計數器(PC)棧指針(SP)…

小白自學python第二天

學習python的第二天 一、判斷語句 1、布爾類型和比較運算符 1、布爾類型 表示現實生活中的邏輯&#xff0c;真&#xff08;True&#xff0c;用數字1表示&#xff09;和假&#xff08;False&#xff0c;用數字0表示&#xff09; 2、布爾類型變量的定義 變量的名稱 布爾類…

linux基礎操作1------(文件命令)

一.前言 我們本章開始講解linux&#xff0c;我們對于linux得有重要的認識&#xff0c;比如項目部署等等&#xff0c;都會用到linux&#xff0c;今天我們就開始linux的學習&#xff0c;我們需要準備的工具有vmware和xshell&#xff0c;而這里我就不教大家虛擬機的安裝以及xshel…

編碼問題整合

一、windows系統編碼 查看編碼命令&#xff1a;chcp - 936 GBK - 65001 UTF-8 - 437 英文修改系統編碼 1、控制面板修改 需管理員權限-Windows 10/11進入 控制面板 > 區域 > 管理 > 更改系統區域設置勾選 Beta版: 使用Unicode UTF-8提供全球語言支持 → 重啟生效修…

如何配置Spark

1.上傳spark安裝包到某一臺機器&#xff08;自己在finaShell上的機器&#xff09;。 2.解壓。 把第一步上傳的安裝包解壓到/opt/module下&#xff08;也可以自己決定解壓到哪里&#xff09;。對應的命令是&#xff1a;tar -zxvf 安裝包 -C /opt/module 3.重命名。進入/opt/mo…

Redis 完整配置模板

一、基礎連接配置&#xff08;單機模式&#xff09; 基礎參數&#xff08;適用Spring Boot&#xff09; spring:redis:host: 127.0.0.1port: 6379password: your_passworddatabase: 0 # 默認DB索引timeout: 2000ms # 全局操作超時時間二、連接池參數&#xff08;通用核心配…

邊界凸臺建模與實例

文章目錄 邊界凸臺特征耳機案例瓶子 邊界凸臺特征 兩側對稱拉伸最上面的圓柱 同過兩點一基準面畫草圖&#xff0c;在基準面上畫橢圓 隱藏無關的實體和草圖&#xff0c;以便橢圓的端點能與線給穿透約束&#xff0c;下面的點與下面的線也給穿透&#xff0c;短軸長給35&#xff08…

河北省大數據應用創新大賽樣題

** 河北省大數據應用創新大賽樣題 ** 1. 在Linux下安裝Java并搭建完全分布式Hadoop集群。在Linux終端執行命令“initnetwork”&#xff0c;或雙擊桌面上名稱為“初始化網絡”的圖標&#xff0c;初始化實訓平臺網絡。 【數據獲取】 使用wget命令獲取JDK安裝包&#xff1a; “w…

【數據可視化-21】水質安全數據可視化:探索化學物質與水質安全的關聯

&#x1f9d1; 博主簡介&#xff1a;曾任某智慧城市類企業算法總監&#xff0c;目前在美國市場的物流公司從事高級算法工程師一職&#xff0c;深耕人工智能領域&#xff0c;精通python數據挖掘、可視化、機器學習等&#xff0c;發表過AI相關的專利并多次在AI類比賽中獲獎。CSDN…

DC-2尋找Flag1、2、3、4、5,wpscan爆破、git提權

一、信息收集 1、主機探測 arp-scan -l 探測同網段2、端口掃描 nmap -sS -sV 192.168.66.136 80/tcp open http Apache httpd 2.4.10 ((Debian)) 7744/tcp open ssh OpenSSH 6.7p1 Debian 5deb8u7 (protocol 2.0)這里是掃描出來兩個端口&#xff0c;80和ssh&…

SQLMesh 表格對比指南:深入理解 table_diff 工具的實際應用

在數據集成和轉換過程中&#xff0c;確保數據模型的一致性和準確性至關重要。SQLMesh 提供了一個強大的 table_diff 工具&#xff0c;可以幫助用戶比較 SQLMesh 模型或數據庫表/視圖的架構和數據。本文將通過具體示例詳細說明如何使用 table_diff 工具進行跨環境比較和直接比較…

重構智能場景:艾博連攜手智譜,共拓智能座艙AI應用新范式

2025年4月24日&#xff0c;智能座艙領域創新企業艾博連科技與國產大模型獨角獸智譜&#xff0c;在上海國際車展艾博連會客廳簽署合作協議。雙方宣布將深度整合智譜在AI大模型領域的技術積淀與艾博連在汽車智能座艙場景的落地經驗&#xff0c;共同推進下一代"有溫度、懂需求…

vscode flutter 插件, vscode運行安卓項目,.gradle 路徑配置

Flutter Flutter Widget Snippets Awesome Flutter Snippets i dart-import Dart Data Class Generator Json to Dart Model Dart Getters And Setter GetX Snippets GetX Generator GetX Generator for Flutter flutter-img-syncvscode運行安卓項目&#xff0c;.gradle 路徑配…

Parasoft C++Test軟件單元測試_對函數打樁的詳細介紹

系列文章目錄 Parasoft C++Test軟件靜態分析:操作指南(編碼規范、質量度量)、常見問題及處理 Parasoft C++Test軟件單元測試:操作指南、實例講解、常見問題及處理 Parasoft C++Test軟件集成測試:操作指南、實例講解、常見問題及處理 進階擴展:自動生成靜態分析文檔、自動…

c# TI BQFS文件格式詳解及C#轉換

FlashStream文件格式詳解及C#轉換 一、FlashStream文件格式詳細解讀 文件概述 FlashStream文件是TI用于配置電池電量計的文本文件格式,主要特點: ? 純文本格式,使用ASCII字符? 每行一條指令 ? 分號(;)開頭的行為注釋 ? 主要包含三種指令類型:寫命令、比較命令和延時…

k8s中pod報錯 FailedCreatePodSandBox

問題現象&#xff1a; 創建容器時出現一下情況 而且刪掉控制器的時候pod還會卡住 解決&#xff1a; 將calico的pod重新刪掉。其中有1個控制器pod以及3個node pod 刪掉后&#xff0c;大概10來秒就重新創建完成了。 然后現在在使用kubectl apply -f 文件.yaml 就可以正常創…

分布式事務 兩階段提交協議(2PC的原理、挑戰)

引言&#xff1a;分布式事務的挑戰 在分布式系統中&#xff0c;數據和服務往往分布在多個節點上。例如&#xff0c;一個電商下單操作可能涉及訂單服務、庫存服務和支付服務&#xff0c;這三個服務需要協同完成一個事務&#xff1a;要么全部成功&#xff0c;要么全部失敗。這種…

Jenkins Pipeline 構建 CI/CD 流程

文章目錄 jenkins 安裝jenkins 配置jenkins 快速上手在 jenkins 中創建一個新的 Pipeline 作業配置Pipeline運行 Pipeline 作業 Pipeline概述Declarative PipelineScripted Pipeline jenkins 安裝 安裝環境&#xff1a; Linux CentOS 10&#xff1a;Linux CentOS9安裝配置Jav…

【CF】Day43——Codeforces Round 906 (Div. 2) E1

E1. Doremys Drying Plan (Easy Version) 題目&#xff1a; 思路&#xff1a; very好題&#xff0c;加深對掃描線的應用&#xff0c;值得深思 由于k 2&#xff0c;那我們就可以使用簡單一點的方法來寫 題目可以轉化為&#xff1a;給定n個線段&#xff0c;現在讓你刪去2條線段…