`
fastwind
  • 浏览: 319117 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

c#加密 可逆与不可逆MD5 加密

阅读更多

1、方法一 (不可逆加密) srxljl

 

 

public string EncryptPassword(string PasswordString,string PasswordFormat )
   
...{
   
string        encryptPassword = null;
   
if (PasswordFormat="SHA1")...{
         encryptPassword
=FormsAuthortication.HashPasswordForStoringInConfigFile(PasswordString ,"SHA1");
         }

         elseif (PasswordFormat
="MD5")
   
...{ encryptPassword=FormsAuthortication.HashPasswordForStoringInConfigFile(PasswordString ,"MD5");
         }

return encryptPassword ;
}

 

2、方法二 (可逆加密)srxljl

 

    public interface IBindesh
...{
    
string encode(string str);
    
string decode(string str);
}


public class EncryptionDecryption : IBindesh
    
...{
        
public string encode(string str)
        
...{
            
string htext = "";

            
for ( int i = 0; i < str.Length; i++)
            
...{
                      htext
= htext + (char) (str[i] + 10 - 1 * 2);
                  }

            
return htext;
              }


        
public string decode(string str)
        
...{
            
string dtext = "";

            
for ( int i=0; i < str.Length; i++)
            
...{
                      dtext
= dtext + (char) (str[i] - 10 + 1*2);
                  }

            
return dtext;
              }

 

3、方法三 (可逆加密)srxljl

 

        
        
const string KEY_64 = "VavicApp";//注意了,是8个字符,64位

        
const string IV_64 = "VavicApp";
public string Encode(string data)
        
...{
            
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
            
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);

                  DESCryptoServiceProvider cryptoProvider
= new DESCryptoServiceProvider();
            
int i = cryptoProvider.KeySize;
                  MemoryStream ms
= new MemoryStream();
                  CryptoStream cst
= new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);

                  StreamWriter sw
= new StreamWriter(cst);
                  sw.Write(data);
                  sw.Flush();
                  cst.FlushFinalBlock();
                  sw.Flush();
            
return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);

              }


        
public string Decode(string data)
        
...{
            
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
            
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);

            
byte[] byEnc;
            
try
            
...{
                      byEnc
= Convert.FromBase64String(data);
                  }

            
catch
            
...{
                
return null;
                  }


                  DESCryptoServiceProvider cryptoProvider
= new DESCryptoServiceProvider();
                  MemoryStream ms
= new MemoryStream(byEnc);
                  CryptoStream cst
= new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
                  StreamReader sr
= new StreamReader(cst);
            
return sr.ReadToEnd();
              }

 

4,md5(32位加密) srxljl

public string GetMD5(string s, string _input_charset)
    
...{

        
/**//// <summary>
        
/// 与ASP兼容的MD5加密算法
        
/// </summary>


             MD5 md5
= new MD5CryptoServiceProvider();
        
byte[] t = md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(s));
             StringBuilder sb
= new StringBuilder(32);
        
for (int i = 0; i < t.Length; i++)
        
...{
                 sb.Append(t[i].ToString(
"x").PadLeft(2, '0'));
             }

        
return sb.ToString();
         }

        (16位加密)srxljl

 

public static string GetMd5Str(string ConvertString)
    
...{
             MD5CryptoServiceProvider md5
= new MD5CryptoServiceProvider();
        
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
             t2
= t2.Replace("-", "");
        
return t2;
         }

 

5、加解文本文件srxljl

 

    //加密文件
    private static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV)
    
...{
        
//Create the file streams to handle the input and output files.
             FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
             FileStream fout
= new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
             fout.SetLength(
0);

        
//Create variables to help with read and write.
        byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
        long rdlen = 0;              //This is the total number of bytes written.
        long totlen = fin.Length;    //This is the total length of the input file.
        int len;                     //This is the number of bytes to be written at a time.

             DES des
= new DESCryptoServiceProvider();
             CryptoStream encStream
= new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);

        
//Read from the input file, then encrypt and write to the output file.
        while (rdlen < totlen)
        
...{
                 len
= fin.Read(bin, 0, 100);
                 encStream.Write(bin,
0, len);
                 rdlen
= rdlen + len;
             }


             encStream.Close();
             fout.Close();
             fin.Close();
         }


    
//解密文件
    private static void DecryptData(String inName, String outName, byte[] desKey, byte[] desIV)
    
...{
        
//Create the file streams to handle the input and output files.
             FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
             FileStream fout
= new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
             fout.SetLength(
0);

        
//Create variables to help with read and write.
        byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
        long rdlen = 0;              //This is the total number of bytes written.
        long totlen = fin.Length;    //This is the total length of the input file.
        int len;                     //This is the number of bytes to be written at a time.

             DES des
= new DESCryptoServiceProvider();
             CryptoStream encStream
= new CryptoStream(fout, des.CreateDecryptor(desKey, desIV), CryptoStreamMode.Write);

        
//Read from the input file, then encrypt and write to the output file.
        while (rdlen < totlen)
        
...{
                 len
= fin.Read(bin, 0, 100);
                 encStream.Write(bin,
0, len);
                 rdlen
= rdlen + len;
             }


             encStream.Close();
             fout.Close();
             fin.Close();
         }

 

 

分享到:
评论

相关推荐

    基于matlab实现的数值计算及金融运用 ,金融时间序列数据分析 ,MATLAB和其他软件数据连接.rar

    基于matlab实现的数值计算及金融运用 ,金融时间序列数据分析 ,MATLAB和其他软件数据连接.rar

    使用SegNet进行语义分割-python源码.zip

    使用SegNet进行语义分割-python源码.zip

    JSP企业电子投票系统 2.zip

    JSP企业电子投票系统 2

    EmotionVGGnet情绪识别-python源码.zip

    EmotionVGGnet情绪识别-python源码.zip

    基于matlab实现的遗传算法、模拟退火算法、禁忌搜索算法求解VRP问题的matlab程序.rar

    基于matlab实现的遗传算法、模拟退火算法、禁忌搜索算法求解VRP问题的matlab程序.rar

    大数据Python科学计算库-Numpy实战:numpy代码

    大数据Python科学计算库-Numpy实战:numpy代码 练习题.ipynb 9-读写.ipynb 8-随机模块.ipynb 7-运算.ipynb 6-数组 生成.ipynb 5-数组形状.ipynb 4-排序.ipynb 3-数值计算. ipynb 2-array结构.ipynb 1-Numpy概述.ipynb 1- Numpy概述.ipynb 2-array结构.ipynb 3-数值计算.ipy nb 4-排序.ipynb 5-数组形状.ipynb 6-数组生成.ipynb 7-运算.ipynb 8-随机模块.ipynb 9-读写.ipynb 练习题.i pynb

    基于统计分析的地面搜索最短耗时的计算方案设计.doc

    本文档是课题研究的研究报告内含调研以及源码设计以及结果分析

    基于BlazePose+KNN实现人体姿态健身计数算法python源码+项目说明.zip

    基于BlazePose+KNN实现人体姿态健身计数算法python源码+项目说明.zip 项目描述: 实现基于mediapipe的人体姿态识别的AI健身自动计数功能 支持健身动作:1、俯卧撑 2、深蹲 3、引体向上 4、仰卧起坐 创建时间:2022.11.28 完成时间:2022.11.28 如何训练新的健身动作模型? 1、修改mian函数 2、首先在fitness_pose_images_in的文件夹下存储对应健身的初态动作与末态动作图像 3、修改videoprocess.py文件中的代码,flag模式选择部分,注意class_name必须与fitness_pose_images_in文件夹下的文件名字保持一致 4、修改videoprocess.py文件中的代码,flag模式选择部分,注意class_name必须与fitness_pose_images_in文件夹下的文件名字保持一致 5、修改trainingsetprocess.py文件中的代码,flag模式选择部分,注意 文件名 必须与fitness_pose_images_in文件夹下的文件名字保持一

    dijkstra 算法说明和基础应用介绍.docx

    Dijkstra 算法,又称为迪杰斯特拉算法,是一种用于解决单源最短 路径问题的经典算法。它的核心思想是通过逐步确定起点到其他顶 点的最短路径来求解。该算法被广泛应用于图论和网络路由等领域。 Dijkstra 算法的基本步骤如下: 1. 创建一个距离数组 dist[] ,用于存储起点到各个顶点的最短距离。 将起点的最短距离初始化为 0,其他顶点的最短距离初始化为无穷 大。 2. 创建一个集合 S ,用于存储已经找到最短路径的顶点。 3. 重复以下步骤,直到集合 S 包含所有顶点: a. 从距离数组 dist[]中选择最小值对应的顶点 v,将 v 加入集合 S。 b. 更新距离数组 dist[] : - 对于每个与 v 相邻的顶点 u,如果通过顶点 v 可以获得更短的 路径,则更新 dist[u]为更短的距离。 c. 重复步骤 a 和 b,直到集合 S 包含所有顶点。 4. 最终,距离数组 dist[]中存储的就是起点到各个顶点的最短路径。 下面通过一个简单的例子来说明 Dijkstra 算法的具体过程。假设有 一个带权有向图,其中的顶点和边分别如下所示:

    node-v12.6.0-linux-s390x.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    IEC 60695-11-3:2012.pdf

    IEC 60695-11-3:2012.pdf

    机械设计电话自动组装产线非常好的设计图纸100%好用.zip

    机械设计电话自动组装产线非常好的设计图纸100%好用.zip

    Editor下载非常好用的工具

    010editor是一款小巧专业的实用型编程工具,010editor官方版功能强悍,便捷好用,支持用户进行编辑十六进制和二进制,可选择自己需要的进制进行编辑,还可对任何的文件进行编辑。

    2007-2022各省份节能环保支出及占一般预算支出比例

    点上面 附件图标,上传附件后可设置现金定价 2007-2022年各省份节能环保 支出占一般预算支出面板数据 已经整理成省级面板数据 手动整理不易

    node-v10.17.0-sunos-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    保护大堡礁(pytorch + yolov5训练自定义数据集)-python源码.zip

    保护大堡礁(pytorch + yolov5训练自定义数据集)-python源码.zip

    PPT经典背景音乐库 视台常用图片呈现背景音乐 雄伟大气的曲子

    PPT经典背景音乐库 名称: 电视台常用图片呈现背景音乐 名称: 雄伟大气的曲子

    unet + pytorch 一个实例-python源码.zip

    unet + pytorch 一个实例-python源码.zip

    基于matlab实现的数学形态滤波器用于旋转机械的振动信号的降噪.rar

    基于matlab实现的数学形态滤波器用于旋转机械的振动信号的降噪.rar

    jsp高校学生考勤管理系统设计与实现(源代码+论文).zip

    jsp高校学生考勤管理系统设计与实现(源代码+论文)

Global site tag (gtag.js) - Google Analytics