網(wǎng)站首頁 編程語言 正文
C#實(shí)現(xiàn)文件加密與解密
代碼:
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#進(jìn)行url加密解密與jquery前端加密解密
當(dāng)我們程序發(fā)布于服務(wù)器上會遇到前端報(bào)錯(cuò)。因?yàn)橛刑厥庠驅(qū)е隆?/p>
此時(shí)需要對傳輸?shù)臄?shù)據(jù),進(jìn)行加密,后臺進(jìn)行解密處理
C#進(jìn)行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編碼
總結(jié)
原文鏈接:https://blog.csdn.net/qq_43024228/article/details/106568590
相關(guān)推薦
- 2022-09-14 python與xml數(shù)據(jù)的交互詳解_python
- 2022-08-30 new Socket(host, port)阻塞解決
- 2022-04-08 WPF中Style樣式及其觸發(fā)器_基礎(chǔ)應(yīng)用
- 2022-09-17 Redis實(shí)現(xiàn)消息的發(fā)布訂閱原理分析_Redis
- 2023-07-25 適用SpringMVC實(shí)現(xiàn)圖片上傳功能
- 2023-05-22 解決The?Network?Adapter?could?not?establish?the?conn
- 2022-01-13 出現(xiàn)/usr/lib64/erlang/erts-10.3/bin/beam.smp: error
- 2022-09-16 Pandas索引排序?df.sort_index()的實(shí)現(xiàn)_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支