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. 【转】statfs获得硬盘使用情况 模拟linux命令 df

    原文网址:http://blog.csdn.net/mociml/article/details/5335474 说明:本文以主要为转载内容,同时加入了我在使用过程中遇到问题对其的修正!!!!!!!! ...

  2. xcode升级,报错 libxml/tree.h not found (Xcode4.6解决方案)

    转:http://blog.csdn.net/yangxuanlun/article/details/8639075 Xcode升级到4.6以后,他妈的,libxml/tree.h找不到了,搞了大半天 ...

  3. Android-onTouchEvent方法的使用

    手机屏幕事件的处理方法onTouchEvent.该方法在View类中的定义,并且所有的View子类全部重写了该方法,应用程序可以通过该方法处理手机屏幕的触摸事件.该方法的签名如下所示. public ...

  4. 基于Spring AOP实现对外接口的耗时监控

    AOP是Spring的核心,Spring不但自身对多种框架的集成是基于AOP,并且以非常方便的形式暴露给普通使用者.以前用AOP不多,主要是因为它以横截面的方式插入到主流程中,担心导致主流程代码不够清 ...

  5. CMake实践(2)

    一,本期目标: [~@localhost t2]$ cat README this is README├── CMakeLists.txt├── COPYRIGHT├── doc│   └── hel ...

  6. 指针和引用的比较(P105)

    指针和引用的比较? 虽然使用引用和指针都可间接访问另一个值,但它们之间有两个重要区别. 第一个区别在于引用总是指向某个对象:定义引用时没有初始化是错误的. 第二个重要区别则是赋值行为的差异:给引用赋值 ...

  7. 《Python核心编程》 第三章 Python基础 - 练习

    创建文件: # -*- coding: gbk -*- #! /auto/ERP/python_core/chapter ''' Created on 2014年5月21日 @author: user ...

  8. bzoj 1798 [Ahoi2009]Seq 维护序列seq(线段树+传标)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1798 [题意] 给定一个序列,要求提供区间乘/加,以及区间求和的操作 [思路] 线段树 ...

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

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

  10. 第二百八十四天 how can I 坚持

    又是一个周一.今天感觉过得好艰辛啊,幸好晚上程秀通过生日请客,吃了顿大餐,还拿回了一瓶酒.哈哈. 其他也没什么了.晚上玩的挺好.不过,回来,老是渴,一直想喝水,现在是又困,又累啊,睡觉了.