当前位置:网站首页>C # create and read dat file cases
C # create and read dat file cases
2022-07-26 19:25:00 【Dusk and starry sky】
*.DAT We can also understand the meaning of the suffix, that is :data file , Data files ; Some of this file can be opened with Notepad tool , But not necessarily after encryption .
Many programs are created dat File to save the settings . Create one that only you can parse dat file , And can read and write , Write a class , It can create a class that can only be resolved by using dat file . Simultaneously read or write data into dat When you file , You can only use this class to read and write . Simply put, this class is to open read write this dat Key to document ! In fact, the file suffixes used to save settings can be various .
1、 Create file read / write classes , As shown below
///
/// encryption 、 Decrypt
///
public class EncrytUtilSeal {
private static byte[] key = new byte[] { 78, 56, 61, 94, 12, 88, 56, 63, 66, 111, 102, 77, 1, 186, 97, 45 };
private static byte[] iv = new byte[] { 36, 34, 42, 122, 242, 87, 2, 90, 59, 117, 123, 63, 72, 171, 130, 61 };
private static IFormatter S_Formatter = null;
static EncrytUtilSeal() {
S_Formatter = new BinaryFormatter();// Create a serialized object
}
///
/// use Rijndael128 Bit encrypted binary serializable object to file
///
/// Binary object
/// File path
///
public static bool EncryptObject(object para, string filePath)
{
// establish .bat file If there had been .bat The file overwrites , Nothing creates
using (Stream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream csEncrypt = new CryptoStream(fs, RMCrypto.CreateEncryptor(key, iv), CryptoStreamMode.Write);
S_Formatter.Serialize(csEncrypt, para);// Serialize the data and send it to csEncrypt
csEncrypt.Close();
fs.Close();
return true;
}
}
///
/// From the adoption of Rijndael128 Bit encrypted files read binary objects
///
/// File path
/// Binary object
public static object DecryptObject(string filePath)
{
// open .bat file
using (Stream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
object para;
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream csEncrypt = new CryptoStream(fs, RMCrypto.CreateDecryptor(key, iv), CryptoStreamMode.Read);
para = S_Formatter.Deserialize(csEncrypt); // take csEncrypt Deserialize back to the original data format ;
csEncrypt.Close();
fs.Close();
return para;
}
}
}
2、 Design read and write buttons in the interface :
The implementation of click events is as follows 
3、 The running results are as follows 

5、 The reading result is as follows 
6、 Because it is an encrypted file , So it's garbled when opening , As shown below :
边栏推荐
- Complete MySQL database commands
- 节约gas-ChiToken的用法
- [C language implementation] - dynamic / file / static address book
- ReentrantLock学习之---基础方法
- 密码一致,总显示如下图
- Detailed explanation of MySQL master-slave replication configuration
- 节省50%成本 京东云发布新一代混合CDN产品
- “蔚来杯“2022牛客暑期多校训练营2
- EN 1504-6混凝土结构保护和修理用产品钢筋锚固—CE认证
- ReentrantLock学习之公平锁过程
猜你喜欢

C#上位机开发—— 修改窗口图标和exe文件图标

Advanced template (runner's notes)

PMP每日一练 | 考试不迷路-7.26(包含敏捷+多选)

The role of @requestmapping in the project and how to use it

LeetCode简单题之验证回文字符串 Ⅱ

Mathematical basis of deep learning

C language - Introduction - syntax - string (11)

Distributed transaction Seata

C # get local time / system time

Write a starter
随机推荐
2022 tea master (intermediate) examination question simulation examination question bank and answers
Reentrantlock learning - lock release process
Here comes the most complete introduction to MES system
Redis learning notes-2. Use of the client
The difference between advanced anti DDoS server and advanced anti DDoS IP
Advanced template (runner's notes)
“蔚来杯“2022牛客暑期多校训练营1
千万不要随便把 Request 传递到异步线程里面 , 有坑 你拿捏不住,得用 startAsync 方法才行
torch. Usage and comparison of unsqueeze() squeeze() expand() repeat()
高防服务器和高防IP的区别
After the exam on June 25, see how the new exam outline reviews PMP
Article 7:exited on desktop-dff5kik with error code -1073741511
Introduction to Seata
C#上位机开发—— 修改窗口图标和exe文件图标
C#中关闭窗体的四种方法
Cannot find current proxy: Set ‘exposeProxy‘ property on Advised to ‘true‘ to make it available
节约gas-ChiToken的用法
What do indicators and labels do
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
Write a starter