C#实现的MD5加密功能与用法示例
作者:pan_junbiao 时间:2023-06-11 09:08:21
本文实例讲述了C#实现的MD5加密功能与用法。分享给大家供大家参考,具体如下:
1、创建MD5Str.cs加密处理类
public class MD5Str
{
/// <summary>
/// 字符串MD5加密
/// </summary>
/// <param name="Text">要加密的字符串</param>
/// <returns>密文</returns>
public static string MD5(string Text)
{
byte[] buffer = System.Text.Encoding.Default.GetBytes(Text);
try
{
System.Security.Cryptography.MD5CryptoServiceProvider check;
check = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] somme = check.ComputeHash(buffer);
string ret = "";
foreach (byte a in somme)
{
if (a < 16)
ret += "0" + a.ToString("X");
else
ret += a.ToString("X");
}
return ret.ToLower();
}
catch
{
throw;
}
}
}
2、运行测试
static void Main(string[] args)
{
string data = "123456789"; //要加密的数据
string encodeStr = ""; //加密后文本
encodeStr = MD5Str.MD5(data);
Console.WriteLine("原文本:{0}", data);
Console.WriteLine("加密后文本:{0}", encodeStr);
Console.Read();
}
PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:
MD5在线加密工具:
http://tools.jb51.net/password/CreateMD5Password
迅雷、快车、旋风URL加密/解密工具:
http://tools.jb51.net/password/urlrethunder
在线散列/哈希算法加密工具:
http://tools.jb51.net/password/hash_encrypt
在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.jb51.net/password/hash_md5_sha
在线sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.jb51.net/password/sha_encode
希望本文所述对大家C#程序设计有所帮助。
标签:C#,MD5加密
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java读写Windows共享文件夹的方法实例
2022-10-02 02:25:45
unity实现UI元素跟随3D物体
2021-11-15 02:00:48
![](https://img.aspxhome.com/file/2023/4/98184_0s.gif)
SpringMVC MVC架构与Servlet使用详解
2023-10-10 15:25:02
![](https://img.aspxhome.com/file/2023/1/61301_0s.png)
Java 程序员掌握 Spring Boot非常有必要
2021-06-27 19:06:52
![](https://img.aspxhome.com/file/2023/1/113511_0s.png)
C#中new操作符的工作机制
2023-12-08 13:57:20
![](https://img.aspxhome.com/file/2023/0/113790_0s.png)
Java NIO:浅析IO模型_动力节点Java学院整理
2022-01-17 17:07:38
![](https://img.aspxhome.com/file/2023/8/65178_0s.png)
将java项目打包成exe可执行文件的完整步骤
2021-11-10 03:48:04
![](https://img.aspxhome.com/file/2023/4/122324_0s.png)
Java Integer及int装箱拆箱对比
2023-04-22 04:21:11
c#入门之分支语句使用方法(三元运算符、if语句、switch语句)
2021-12-06 00:55:20
Java利用apache ftp工具实现文件上传下载和删除功能
2022-03-17 02:04:01
关于SpringBoot静态资源路径管理问题
2022-12-04 03:51:29
![](https://img.aspxhome.com/file/2023/1/92551_0s.png)
浅谈BeanPostProcessor加载次序及其对Bean造成的影响分析
2022-05-02 19:52:29
工作中禁止使用Executors快捷创建线程池原理详解
2021-11-24 20:55:48
![](https://img.aspxhome.com/file/2023/9/75439_0s.png)
Java生成含字母和数字的6位随机字符串
2023-04-02 02:28:58
java创建多级目录文件的实例讲解
2023-11-27 09:29:02
Android中EditText光标的显示与隐藏方法
2022-03-01 17:52:35
C#代码设置开机启动示例
2021-12-16 17:53:07
![](https://img.aspxhome.com/file/2023/1/108621_0s.jpg)
C# log4net日志库的用法小结
2023-12-26 18:50:44
![](https://img.aspxhome.com/file/2023/0/113810_0s.jpg)
Mybatis 入门之MyBatis环境搭建(第一篇)
2023-03-15 16:09:32
![](https://img.aspxhome.com/file/2023/6/66216_0s.png)
JAVA实现301永久重定向方法
2023-12-18 10:59:08