網站首頁 編程語言 正文
C#實現文件加密與解密
代碼:
static class HandleFiles
{
public static void EncryptFile(string inputFile, string outputFile) //加密
{
try
{
string password = @"12345678";
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsIn.Close();
cs.Close();
fsCrypt.Close();
MessageBox.Show("Encrypt Source file succeed!", "Msg :");
}
catch(Exception ex)
{
MessageBox.Show("Source file error!", "Error :");
}
}
public static void DecryptFile(string inputFile, string outputFile) //解密
{
try
{
string password = @"12345678";
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateDecryptor(key, key),
CryptoStreamMode.Read);
FileStream fsOut = new FileStream(outputFile, FileMode.Create);
int data;
while ((data = cs.ReadByte()) != -1)
fsOut.WriteByte((byte)data);
fsOut.Close();
cs.Close();
fsCrypt.Close();
MessageBox.Show("Decrypt Source file succeed!", "Msg :");
}
catch(Exception ex)
{
MessageBox.Show("Source file error", "Error :");
}
}
}
C#進行url加密解密與jquery前端加密解密
當我們程序發布于服務器上會遇到前端報錯。因為有特殊原因導致。
此時需要對傳輸的數據,進行加密,后臺進行解密處理
C#進行url加密與解密
HttpUtility.UrlEncode(val); ?//utf-8 編碼
HttpUtility.UrlDecode(val); ?//utf-8 解碼
HttpUtility.UrlEncode(val, System.Text.Encoding.GetEncoding(936)); ?//gb2312編碼
HttpUtility.UrlDecode(val, System.Text.Encoding.GetEncoding(936)); ?//gb2312解碼
System.Web.HttpUtility.UrlEncode(val, System.Text.Encoding.GetEncoding("GB2312"));//gb2312編碼
System.Web.HttpUtility.UrlDecode(val, System.Text.Encoding.GetEncoding("GB2312"));//gb2312解碼
jquery
decodeURIComponent(val);//Jquery解碼
encodeURIComponent(val);//Jquery編碼
總結
原文鏈接:https://blog.csdn.net/qq_43024228/article/details/106568590
相關推薦
- 2022-04-12 C#實現六大設計原則之迪米特法則_C#教程
- 2022-05-20 死鎖的產生和避免
- 2023-02-07 Go?singleflight使用以及原理_Golang
- 2022-06-08 Spring Cloud Nacos 配置動態刷新
- 2023-07-28 el-table 合并單元格(合并行)
- 2023-07-14 react封裝一個router6
- 2022-07-01 淺談C語言中的sizeof()和strlen()的區別_C 語言
- 2023-04-24 Python中__init__的用法和理解示例詳解_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支