C# MD5加密解密帮助类
/// <summary>
/// MD5加密解密帮助类
/// </summary>
public static class DESHelper
{
/// <summary>
/// MD5加密
/// </summary>
/// <param name="pToEncrypt"></param>
/// <param name="sKey">密钥(8位字符)</param>
/// <returns></returns>
public static string MD5Encrypt(string pToEncrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
/// <summary>
/// MD5解密
/// </summary>
/// <param name="pToDecrypt"></param>
/// <param name="sKey">密钥(8位字符)</param>
/// <returns></returns>
public static string MD5Decrypt(string pToDecrypt, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
for (int x = 0; x < pToDecrypt.Length / 2; x++)
{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
return System.Text.Encoding.Default.GetString(ms.ToArray());
}
/// <summary>
/// 获取Key
/// </summary>
/// <returns></returns>
public static string GetKey()
{
return "wanghuai";
}
}
C# MD5加密解密帮助类的更多相关文章
- MD5加密解密帮助类
using System; using System.Security.Cryptography; using System.Text; namespace Maticsoft.DBUtility { ...
- php加密解密处理类
[PHP]代码 <?php /*=========================================================== = 版权协议: = GPL (The GN ...
- DES加密解密 MD5加密解密
#region MD5 加密 /// <summary> /// MD5加密静态方法 /// </summary> /// <param name="Encry ...
- php加密解密功能类
这两天突发奇想想要用php写一个对日常项目加密以及解密的功能,经过努力简单的封装了一个对php代码进行加密解密的类,一些思想也是来自于网络,初步测试用着还行,可以实现对指定项目的加密以及解密(只针对本 ...
- java 采用MD5加密解密
MD5加密解密 package endecrypt; import java.io.UnsupportedEncodingException; import java.security.Message ...
- AES加密解密 助手类 CBC加密模式
"; string result1 = AESHelper.AesEncrypt(str); string result2 = AESHelper.AesDecrypt(result1); ...
- .Net(c#)加密解密工具类:
/// <summary> /// .Net加密解密帮助类 /// </summary> public class NetCryptoHelper { #region des实 ...
- Base64加密解密工具类
使用Apache commons codec类Base64进行加密解密 maven依赖 <dependency> <groupId>commons-codec</grou ...
- MD5加密解密类(asp.net)&使用MD5过时处理
加密类 #region ========加密======== /// <summary> /// 加密 /// </summary> /// <param name=&q ...
随机推荐
- AccessRandomFile多线程下载文件
写一个工具类 package com.pb.thread.demo; import java.io.File; import java.io.FileNotFoundException; import ...
- CSS ID选择器(三)
一.ID选择器 ID选择器使用"#"前缀标识符进行标识,后面紧跟指定的元素的ID名称. 如 #box{ width:100px; height:100px;} 元素的ID名称是唯一 ...
- maven 错误No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------- ...
- 手机远程调试工具spy-debugger
关于spy-debugger 1.一站式页面调试工具,远程调试任何手机浏览器页面,任何手机移动端webview(如:微信,HybirdApp等)HTTP/HTTPS.2.spy-debugger内 ...
- sqlserver2008链接服务器的使用和oracle11g客户端修改字符集
1.服务器对象-链接服务器-访问接口-(OracleDB.Oracle)属性-允许进程内 2.运行-regedit-HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE-NIS_LAN ...
- 烂泥:【解决】word复制windows live writer没有图片
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在使用windows live writer发表博客,博客先是在是word2013中进行编辑,编辑完毕后我会复制到windows live writer ...
- 有关Azure存储帐号监视器中的度量值
在一次故障排错中,发现存储帐号监视器里'成功百分比'(该度量值的源选择的是blob)这个度量值始终是低于100%.引出几个问题: 1. 这个度量值所代表的意义? A: 存储基于REST协议,对服务的访 ...
- Ubuntu 安装JDK并配置成为默认的JDK
Ubuntu安装JDK 系统版本:Ubuntu 15.04 x64 JDK版本:jdk-8u60-linux-x64 1.查看系统位数,输入以下命令即可 getconf LONG_BIT 2.下载对应 ...
- php session文件修改路径
默认状态下php的 sess_文件会生成到/tmp目录下,1天的时间就会生成很多,由于/tmp目录下还有别的重要文件,所以看起来不爽.具体更改做法是,找到 php.ini文件里面的session.sa ...
- 使用Azure Automation(自动化)定时关闭和启动虚拟机
1. 概述 作为Windows Azure的用户,使用Azure的过程中,最担心的事情就是还没到月底,预设的费用就快消耗完了(下面两张账单图是我最讨厌看到的).但是仔细分析自己的费用列表,发现绝大部分 ...