Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf1e070
commit 6d5c898
Showing
4 changed files
with
394 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace YiSha.Util | ||
{ | ||
public class EncodingHelper | ||
{ | ||
private static string HexStr = "0123456789abcdef"; | ||
private static char[] HexCharArr = HexStr.ToCharArray(); | ||
|
||
public static string ByteArrToHex(byte[] btArr) | ||
{ | ||
char[] strArr = new char[btArr.Length * 2]; | ||
int i = 0; | ||
foreach (byte bt in btArr) | ||
{ | ||
strArr[i++] = HexCharArr[bt >> 4 & 0xf]; | ||
strArr[i++] = HexCharArr[bt & 0xf]; | ||
} | ||
return new string(strArr); | ||
} | ||
|
||
public static byte[] HexToByteArr(string hexStr) | ||
{ | ||
char[] charArr = hexStr.ToCharArray(); | ||
byte[] btArr = new byte[charArr.Length / 2]; | ||
int index = 0; | ||
for (int i = 0; i < charArr.Length; i++) | ||
{ | ||
int highBit = HexStr.IndexOf(charArr[i]); | ||
int lowBit = HexStr.IndexOf(charArr[++i]); | ||
btArr[index] = (byte)(highBit << 4 | lowBit); | ||
index++; | ||
} | ||
return btArr; | ||
} | ||
|
||
public static string ByteArrToHexDefault(byte[] btArr) | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
foreach (byte b in btArr) | ||
{ | ||
sb.Append(b.ToString("X2")); | ||
} | ||
return sb.ToString(); | ||
} | ||
|
||
public static byte[] HexToByteArrDefault(string hexStr) | ||
{ | ||
byte[] inputArr = new byte[hexStr.Length / 2]; | ||
for (int i = 0; i < hexStr.Length / 2; i++) | ||
{ | ||
int v = Convert.ToInt32(hexStr.Substring(i * 2, 2), 16); | ||
inputArr[i] = (byte)v; | ||
} | ||
return inputArr; | ||
} | ||
} | ||
} |
Oops, something went wrong.
6d5c898
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, SecurityHelper.cs中的方法GetGuid(bool replaceDash = false)
replaceDash默认是false的话不会替换掉GUID中的“-”,字符串长度为36位,数据库里WebToken是varchar(32)的,登录时会出现“将截断字符串或二进制数据。 语句已终止。”的提示。是不是默认值设反了或者忘记修改相关调用了~ :)