• Encrypt Decrypt


    encryptstring

                    DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
                    byte[] key = System.Text.Encoding.Unicode.GetBytes(encryptkey);
                    byte[] data = System.Text.Encoding.Unicode.GetBytes(encryptstring);
                    MemoryStream ms = new MemoryStream();//存储加密后的数据
                    CryptoStream cs = new CryptoStream(ms, desc.CreateEncryptor(key, key), CryptoStreamMode.Write);
                    cs.Write(data, 0, data.Length);//进行加密
                    cs.FlushFinalBlock();
                    strRtn = Convert.ToBase64String(ms.ToArray());
                    return strRtn;

    decryptstring

                    DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
                    byte[] key = System.Text.Encoding.Unicode.GetBytes(encryptkey);
                    byte[] data = Convert.FromBase64String(decryptstring);
                    MemoryStream ms = new MemoryStream();//存储解密后的数据
                    CryptoStream cs = new CryptoStream(ms, desc.CreateDecryptor(key, key), CryptoStreamMode.Write);
                    cs.Write(data, 0, data.Length);//解密数据
                    cs.FlushFinalBlock();
                    strRtn = System.Text.Encoding.Unicode.GetString(ms.ToArray());
                    return strRtn;

  • 相关阅读:
    fatal error LNK1123: failure during conversion to COFF: file invalid or corr
    BEGIN_SINK_MAP(CMainDlg) SINK_ENTRY(IDC_EXPLORER1, ..。响应不到的
    第三周项目3-程序的多文件组织
    第三周项目2-三角形类(二)
    第三周项目1-三角形类(一)
    第三周课后实践-阅读程序
    第二周项目4-图书馆的书
    第二周项目3-时间类
    第二周项目2-长方柱类
    第二周项目1-旱冰场造价
  • 原文地址:https://www.cnblogs.com/greencolor/p/1725330.html
Copyright © 2020-2023  润新知