/// <summary> /// Des解密 /// </summary> /// <param name="cipherText"></param> /// <param name="key"></param> /// <param name="plainText"></param> /// <returns></returns> public static bool DesDecrypt(string cipherText, string key, out string plainText) { Encoding utf8 = Encoding.UTF8; try { DesEncodeDecode des = new DesEncodeDecode(key, System.Security.Cryptography.CipherMode.ECB, System.Security.Cryptography.PaddingMode.PKCS7, true, utf8); byte[] input = Base58.Decode(cipherText); byte[] output = des.DesDecrypt(input); plainText = utf8.GetString(output); return(true); } catch (Exception ex) { plainText = ex.Message; return(false); } }
/// <summary> /// 从TOKEN中解密数据 /// </summary> /// <param name="cipherToken"></param> /// <returns></returns> public static UserToken FromCipherToken(string cipherToken) { byte[] input = Base58.Decode(cipherToken); var des = new DesEncodeDecode(SECRET, System.Security.Cryptography.CipherMode.ECB, System.Security.Cryptography.PaddingMode.PKCS7, true); byte[] output = des.DesDecrypt(input); string plainText = Encoding.UTF8.GetString(output); string[] array = plainText.Split('|'); int seconds; int user_id, appid; if (!int.TryParse(array[0], out seconds)) { return(null); } TimeStamp timestamp = seconds; if (!int.TryParse(array[1], out user_id)) { return(null); } if (!int.TryParse(array[3], out appid)) { return(null); } UserToken userToken = new UserToken { Expire_Time = timestamp.LocalDate, UserCode = array[2], UserId = user_id, AppId = appid, Verifiable = (array.Length > 3) ? (array[3] == "1") : false }; return(userToken); }