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();
         }

c#加密 可逆与不可逆MD5 加密的更多相关文章

  1. 16位的MD5加密和32位MD5加密的区别

    16位的MD5加密和32位MD5加密的区别 MD5加密后所得到的通常是32位的编码,而在不少地方会用到16位的编码它们有什么区别呢?16位加密就是从32位MD5散列中把中间16位提取出来!其实破解16 ...

  2. IOS中把字符串加密/IOS中怎么样MD5加密/IOS中NSString分类的实现

    看完过后,你会学到: 1学习IOS开发中的分类实现, 2以及类方法的书写, 3以及字符串的MD5加密/解密. ---------------------------wolfhous---------- ...

  3. java实现DES加密与解密,md5加密

    很多时候要对秘要进行持久化加密,此时的加密采用md5.采用对称加密的时候就采用DES方法了 import java.io.IOException; import java.security.Messa ...

  4. NET实现RSA AES DES 字符串 加密解密以及SHA1 MD5加密

    本文列举了    数据加密算法(Data Encryption Algorithm,DEA) 密码学中的高级加密标准(Advanced EncryptionStandard,AES)RSA公钥加密算法 ...

  5. md5 32位 加密原理 Java实现md5加密

    md5 32位 加密原理 简单概括起来,MD5 算法的过程分为四步:处理原文,设置初始值,循环加工,拼接结果. 第一步:处理原文 首先,我们计算出原文长度(bit)对 512 求余的结果,如果不等于 ...

  6. IOS常见的加密方法,常用的MD5和Base64

    iOS代码加密常用加密方式 iOS代码加密常用加密方式,常见的iOS代码加密常用加密方式算法包括MD5加密.AES加密.BASE64加密,三大算法iOS代码加密是如何进行加密的,且看下文 MD5 iO ...

  7. Android数据加密之MD5加密

    前言: 项目中无论是密码的存储或者说判断文件是否是同一文件,都会用到MD5算法,今天来总结一下MD5加密算法. 什么是MD5加密? MD5英文全称“Message-Digest Algorithm 5 ...

  8. python-os模块及md5加密

    常用内置方法 __doc__打印注释 __package__打印所在包 __cached__打印字节码 __name__当前为主模块是__name__ == __main__ __file__打印文件 ...

  9. MD5加密处理

    无论传送过程和存储方式,都是以明文的方式,很不安全!一旦泄漏,将会造成很大的损失! 插件名称jQuery.MD5.js: /** * jQuery MD5 hash algorithm functio ...

随机推荐

  1. 【转】从INF文件认识驱动

    在工控机安装xp操作系统时,由于工控机的集成显卡驱动只支持win7,之前没接触过windows驱动相关内容,折腾了半天.下载的驱动是exe的,双击安装就提示安装失败(未签名) 上图是网上随便找的,现象 ...

  2. util-判断当前年份所处的季度,并返回当前季度开始的月份

    ylbtech-funcation-util:  判断当前年份所处的季度,并返回当前季度开始的月份 判断当前年份所处的季度,并返回当前季度开始的月份. 1.A,Ylbtech.Model返回顶部 us ...

  3. HDU-4035 Maze

    http://acm.hdu.edu.cn/showproblem.php?pid=4035 树上的概率dp.   Maze Time Limit: 2000/1000 MS (Java/Others ...

  4. 【剑指offer 面试题7】用两个栈实现队列

    #include <iostream> #include <stack> using namespace std; template <typename T> cl ...

  5. 《零成本实现Web自动化测试--基于Selenium》第三章 Selenium-IDE

    1.简介 Selenium-IDE(集成开发环境)是一种开发selenium测试案例的工具.是一种易用的Firefox插件.你可以通过文字菜单,在当前页面上选择一个UI元素,接着挑选与UI元素相关的s ...

  6. SQL数据库面试题以及答案

    Student(stuId,stuName,stuAge,stuSex) 学生表 stuId:学号:stuName:学生姓名:stuAge:学生年龄:stuSex:学生性别 Course(course ...

  7. iOS开发相关图书推荐

    Objective-C编程之道:iOS设计模式解析 作      者 [美] Carlo Chung 著:刘威 译 出 版 社 人民邮电出版社 出版时间 2011-11-01 版      次 1 页 ...

  8. HDU-4749 Parade Show KMP算法 | DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题意:给两个串S和P,求S串中存在多少个与P串的大小关系一样的串. 因为数字的范围是1<= ...

  9. asp.net mvc 实体类成员变量标识示例

    检查不能为空 [Required] public string ID { get; set; } 检查最大长度 [StringLength(36, ErrorMessage = "长度不可超 ...

  10. 2048-AI程序算法分析

    转自:CodingLabs 针对目前火爆的2048游戏,有人实现了一个AI程序,可以以较大概率(高于90%)赢得游戏,并且作者在stackoverflow上简要介绍了AI的算法框架和实现思路.但是这个 ...