C#编程-ini文件读写MD5Encrypt加密、DES加密

本文介绍了一个使用C#实现的INI文件读写及加密解密的类,包括了基本的文件存在检查、节名比较、以及利用DES和MD5进行数据加密的功能。此外,还提供了读写INI文件的具体方法,适用于需要安全存储配置信息的应用场景。
public class Filesini
    {
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string sectionName, string key, string defaultValue, byte[] returnBuffer, int size, string filePath);
 
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string sectionName, string key, string value, string filePath);


        public bool ExistINIFile(string strinipath)
        {
            return File.Exists(strinipath);
        }

        public bool isSameSectionName(string strinipath,string name)
        {
            List<string> listName = GetSectionNames(strinipath);
            if (ExistINIFile(strinipath))
            {
                foreach (string n in listName)
                {
                    if (n == name) {
                       return true;                        
                    }
                }
            }
            return false;
        }

        #region 加密

        #region ini文件DES加密/解密使用中
        // 初始化DES加密的密钥和一个随机的、8比特的初始化向量(IV)
        private byte[] key_8 = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
        private byte[] IV_8 = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };

        public string DES_Encrypt(string encryptString)
        {
            try
            {
                byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
                DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值