using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string s = new Authentication().EncryptionReview("abcdefg"); } //密码验证 public class Authentication { /// <summary> /// 加密签字密码,和OA用户名密码加密机制一样 /// </summary> /// <param name="CodeStr"></param> /// <returns></returns> public string EncryptionReview(string CodeStr) { double NewCode = 1; int CodeLen = 30; int CodeSpace = CodeLen - CodeStr.Length; int Been = 0; string returnstring = ""; for (int i = 1; i <= CodeSpace; i++) { CodeStr = CodeStr + Chr(21); } for (int i = 1; i <= CodeLen; i++) { Been = CodeLen + Convert.ToInt32(Asc(CodeStr.Substring(i - 1, 1))) * i; NewCode = NewCode * Been; } double NewCodes = double.Parse(NewCode.ToString("0.00")); string NewCodee = ""; NewCode = 0; for (int i = 1; i <= Convert.ToString(NewCodes).Length; i++) { if (Convert.ToString(NewCodes).Length - i > 1) { NewCodee = NewCodee + EncryptionReviewa(Convert.ToString(NewCodes).Substring(i - 1, 3)); } else if (Convert.ToString(NewCodes).Length - i == 1) { NewCodee = NewCodee + EncryptionReviewa(Convert.ToString(NewCodes).Substring(i - 1, 2)); } else if (Convert.ToString(NewCodes).Length - i == 0) { NewCodee = NewCodee + EncryptionReviewa(Convert.ToString(NewCodes).Substring(i - 1, 1)); } } for (int i = 20; i <= Convert.ToString(NewCodee).Length - 18; i = i + 2) { returnstring = returnstring + NewCodee.Substring(i - 1, 1); } return returnstring; } private string EncryptionReviewa(string PassStr) { string CfsCode = ""; for (int i = 1; i <= PassStr.Length; i++) { CfsCode = CfsCode + Asc(PassStr.Substring(i - 1, 1)); } return int.Parse(CfsCode).ToString("X"); } private 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."); } } private 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."); } } } }
?
Encoding不是加密`是编码,编码和加密是完全的两个东西.
你去查下怎么算http://baike.baidu.com/link?url=62gCnm5dgWdJX8wmOUmbAUToXrX_VTvsOc1JBAV-W3S7dJua0vz6J5M6tMrYep-W
至于Encoding只要Decoding就行了
怎么根据现有的加密方式在反解密了。
int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
我可不可以理解为这一步是加密的?
解码的方式就是反过来做一次,
加密是:GetBytes(Char[])/GetBytes(string)
解码是:GetChars(Byte[])
怎么根据现有的加密方式在反解密了。
@cheng_doom: 有加密方式就会有相应的解密方式.要看你用的什么加密方法
@吴瑞祥: 就是我贴出的代码啊。