博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
加密解密-C#
阅读量:5064 次
发布时间:2019-06-12

本文共 4321 字,大约阅读时间需要 14 分钟。

public static string Encrypt(string strPWtoEncrypt)        {            string CurrentFunction = "" + CommonSettings.ModNFunComStr + "Encrypt";            try            {                string strPword=string.Empty;                byte bytCount;                int intTemp;                for (bytCount = 1; bytCount <= strPWtoEncrypt.Length; bytCount++)                {                    intTemp = Convert.ToChar(strPWtoEncrypt.Substring(bytCount - 1, 1));                    if (bytCount % 2 == 0)                    {                        intTemp = intTemp - 0;                    }                    else                    {                        intTemp = intTemp + 0;                    }                    intTemp = intTemp ^ (10 - 0);                    strPword = strPword + Chr(intTemp);                }                string strEncrypt = strPword;                strEncrypt = strEncrypt.Replace("\\", "{01}");                strEncrypt = strEncrypt.Replace("/", "{02}");                strEncrypt = strEncrypt.Replace(":", "{03}");                strEncrypt = strEncrypt.Replace("*", "{04}");                strEncrypt = strEncrypt.Replace("?", "{05}");                strEncrypt = strEncrypt.Replace("\"", "{06}");                strEncrypt = strEncrypt.Replace("<", "{07}");                strEncrypt = strEncrypt.Replace(">", "{08}");                strEncrypt = strEncrypt.Replace("|", "{09}");                return strEncrypt;            }            catch (Exception ex)            {                //LogManager.WriteTextLog(CurrentFunction, ex);                return "";            }        }        public static string Decrypt(string strPWtoDecrypt)        {            string CurrentFunction = "" + CommonSettings.ModNFunComStr + "Decrypt";            try            {                string strPword=string.Empty;                byte bytCount;                int intTemp;                strPWtoDecrypt = strPWtoDecrypt.Replace("{01}", "\\");                strPWtoDecrypt = strPWtoDecrypt.Replace("{02}", "/");                strPWtoDecrypt = strPWtoDecrypt.Replace("{03}", ":");                strPWtoDecrypt = strPWtoDecrypt.Replace("{04}", "*");                strPWtoDecrypt = strPWtoDecrypt.Replace("{05}", "?");                strPWtoDecrypt = strPWtoDecrypt.Replace("{06}", "\"");                strPWtoDecrypt = strPWtoDecrypt.Replace("{07}", "<");                strPWtoDecrypt = strPWtoDecrypt.Replace("{08}", ">");                strPWtoDecrypt = strPWtoDecrypt.Replace("{09}", "|");                for (bytCount = 1; bytCount <= strPWtoDecrypt.Length; bytCount++)                {                    intTemp = Convert.ToChar(strPWtoDecrypt.Substring(bytCount - 1, 1));                    intTemp = intTemp ^ (10 - 0);                    if (bytCount % 2 == 0)                    {                        intTemp = intTemp + 0;                    }                    else                    {                        intTemp = intTemp - 0;                    }                                        strPword = strPword + Chr(intTemp);                }                return strPword;            }            catch (Exception ex)            {                //LogManager.WriteTextLog(CurrentFunction, ex);                return "";            }        }        public static int Asc(string character)        {            if (character.Length == 1)            {                System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();                int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];                return (intAsciiCode);            }            else            {                throw new Exception("Character is not valid.");            }        }        public static string Chr(int asciiCode)        {            if (asciiCode >= 0 && asciiCode <= 255)            {                System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();                byte[] byteArray = new byte[] { (byte)asciiCode };                string strCharacter = asciiEncoding.GetString(byteArray);                return (strCharacter);            }            else            {                throw new Exception("ASCII Code is not valid.");            }        }

转载于:https://www.cnblogs.com/blackbean/archive/2011/04/13/2014411.html

你可能感兴趣的文章
Codeforces 719B Anatoly and Cockroaches
查看>>
jenkins常用插件汇总
查看>>
c# 泛型+反射
查看>>
第九章 前后查找
查看>>
Python学习资料
查看>>
多服务器操作利器 - Polysh
查看>>
[LeetCode] Candy
查看>>
Jmeter学习系列----3 配置元件之计数器
查看>>
jQuery 自定义函数
查看>>
jq 杂
查看>>
jquery datagrid 后台获取datatable处理成正确的json字符串
查看>>
作业一
查看>>
AJAX
查看>>
ActiveMQ与spring整合
查看>>
web服务器
查看>>
Git的使用--打tag
查看>>
F# 编程 借助 F# 构建 MVVM 应用程序
查看>>
ACFUN切换代码自用。。。
查看>>
网卡流量检测.py
查看>>
【转】Android的权限permission
查看>>