求des加密的源码,

解决方案 »

  1.   

    DES算法及其在VC++6.0下的实现(上):
    http://www.vckbase.com/document/viewdoc/?id=623
    DES算法及其在VC++6.0下的实现(下):
    http://www.vckbase.com/document/viewdoc/?id=624
      

  2.   

    我上传的源码: http://185435.tomore.com/
      

  3.   

    to :palmax(南宫煌)
    我看过这个代码,我在项目中要把加密好的串传给C#写的程序,由于C#用的是microsoft提供的库写的des加密,所以总和我的串对应不起来.
      

  4.   

    go to baidu or google and type keyword:
    DES 100行
    可以找到用C语言写100行的DES加密算法
      

  5.   

    感谢,楼上的发来的代码,在我的项目中要实现与c#写的程序相互加解密,我试了一下你的代码,得到的加密结果不一样,我对c#的加密不太熟,请大家帮忙看一下
    下面是c#实现的des/// <summary>
    /// Des加密的实现
    /// </summary>
    /// <param name="pToEncrypt">被加密的串,支持中文</param>
    /// <param name="sKey">8位英文字母</param>
    /// <returns>加密后的串</returns>
    static public string DesEncrypt(string pToEncrypt, string sKey)
    {
    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt); //建立加密对象的密钥和偏移量
    //原文使用ASCIIEncoding.ASCII方法的GetBytes方法
    //使得输入密码必须输入英文文本
    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();
    }
      

  6.   


    /// <summary>
    /// Des解密的实现
    /// </summary>
    /// <param name="pToEncrypt">被解密的串,支持中文</param>
    /// <param name="sKey">8位英文字母</param>
    /// <returns>解密后的串</returns>
    static public string DesDecrypt(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();
    //建立StringBuild对象,CreateDecrypt使用的是流对象,必须把解密后的文本变成流对象
    StringBuilder ret = new StringBuilder(); return System.Text.Encoding.Default.GetString(ms.ToArray());
    }
      

  7.   

    借宝地一用.求3DES加密代码的使用方法,不会的帮我顶一下,谢谢!http://community.csdn.net/Expert/topic/4764/4764501.xml?temp=.9552271