本文整理汇总了C#中System.Text.ASCIIEncoding.Split方法的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding.Split方法的具体用法?C# ASCIIEncoding.Split怎么用?C# ASCIIEncoding.Split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.ASCIIEncoding
的用法示例。
在下文中一共展示了ASCIIEncoding.Split方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public List<PageItem> Process(int Flags, byte[] RecordData)
{
MemoryStream _ms = null;
BinaryReader _br = null;
try
{
_ms = new MemoryStream(RecordData);
_br = new BinaryReader(_ms);
Byte[] PrivateData = _br.ReadBytes(RecordData.Length);
//Ok we should have our private data which I am storing my tooltip value in...
//now lets interpret it...
string PData = new System.Text.ASCIIEncoding().GetString(PrivateData);
//If string starts with "ToolTip" then lets do something with it.. otherwise I don't care about it.
if (PData.StartsWith("ToolTip"))
{
PageRectangle pr = new PageRectangle();
StyleInfo si = new StyleInfo();
pr.SI = si;
//si.BackgroundColor = Color.Blue;// Just a test to see where the tooltip is being drawn
string[] ttd = PData.Split('|');
pr.Tooltip = ttd[0].Split(':')[1];
pr.X = X + Single.Parse(ttd[1].Split(':')[1]) * SCALEFACTOR;
pr.Y = Y + Single.Parse(ttd[2].Split(':')[1]) * SCALEFACTOR;
pr.W = Single.Parse(ttd[3].Split(':')[1]) * SCALEFACTOR;
pr.H = Single.Parse(ttd[4].Split(':')[1]) * SCALEFACTOR;
items.Add(pr);
}
else if (PData.StartsWith("PolyToolTip"))
{
PagePolygon pp = new PagePolygon();
StyleInfo si = new StyleInfo();
pp.SI = si;
//si.BackgroundColor = Color.Blue;// Just a test to see where the tooltip is being drawn
string[] ttd = PData.Split('|');
PointF[] pts = new PointF[(ttd.Length - 1) / 2];
pp.Points = pts;
pp.Tooltip = ttd[0].Split(':')[1];
for (int i = 0; i < pts.Length; i++)
{
pts[i].X = X + Single.Parse(ttd[i*2 +1]) * SCALEFACTOR;
pts[i].Y = Y + Single.Parse(ttd[i*2 +2]) * SCALEFACTOR;
}
items.Add(pp);
}
return items;
}
finally
{
if (_br != null)
_br.Close();
if (_ms != null)
_ms.Dispose();
}
}
示例2: OnAuthenticateRequest
// First method OnAuthenticateRequest, that implements authentication logic step 1
/*
####################################################################
# OnAuthenticateRequest
#
#
#
####################################################################
*/
public void OnAuthenticateRequest(object source, EventArgs eventArgs)
{
HttpApplication app = (HttpApplication)source;
// then follow authentication logic
// get Http header "Authorization"
// check if not empty
string authorization = app.Request.Headers["Authorization"];
if ((authorization == null) || (authorization.Length == 0))
{
//AccessDenied(app);
return;
}
// check if Http header has the syntax of basic
authorization = authorization.Trim();
if (!authorization.StartsWith("Basic"))
{
// *** Not validating
return;
}
// cut the word "basic" and decode from base64
// get "username:password"
byte[] tempConverted = Convert.FromBase64String(authorization.Substring(6));
string userInfo = new ASCIIEncoding().GetString(tempConverted);
// get "username"
// get "password"
string[] usernamePassword = userInfo.Split(new char[] { ':' });
string username = usernamePassword[0];
string password = usernamePassword[1];
// compare username, password against the values, stored in the database
// if everything is fine, get user group list from the database
// and create an instance of GenericPrincipal
if (AuthenticateUser(username, password))
{
app.Context.User = new GenericPrincipal(new GenericIdentity(username,
"Custom Basic Authentication"), null);
}
// else, AccessDenied
else
{
AccessDenied(app);
}
}
示例3: OnAuthenticateRequest2
public void OnAuthenticateRequest2(
object source
, EventArgs eventArgs
)
{
HttpApplication app = (HttpApplication)source;
string authHeader = app.Request.Headers["Authorization"];
if (!string.IsNullOrEmpty(authHeader))
{
string authStr = app.Request.Headers["Authorization"];
if (authStr == null || authStr.Length == 0)
{
return;
}
authStr = authStr.Trim();
if (authStr.IndexOf("Basic", 0) != 0)
{
return;
}
authStr = authStr.Trim();
string encodedCredentials = authStr.Substring(6);
byte[] decodedBytes =
Convert.FromBase64String(encodedCredentials);
string s = new ASCIIEncoding().GetString(decodedBytes);
string[] userPass = s.Split(new char[] { ':' });
string username = userPass[0];
string password = userPass[1];
if ( ! Validate(username, password))
{
DenyAccess(app);
return;
}
}
else
{
app.Response.StatusCode = 401;
app.Response.End();
}
}
示例4: Authorize
public bool Authorize(HttpContextBase context)
{
if (!SecurityContext.IsAuthenticated)
{
try
{
//Try basic
var authorization = context.Request.Headers["Authorization"];
if (string.IsNullOrEmpty(authorization))
{
return false;
}
authorization = authorization.Trim();
if (authorization.IndexOf(',')!=-1)
authorization = authorization.Substring(0, authorization.IndexOf(',')).Trim();
if (authorization.IndexOf("Basic", 0) != 0)
{
return false;
}
// cut the word "basic" and decode from base64
// get "username:password"
var tempConverted = Convert.FromBase64String(authorization.Substring(6));
var user = new ASCIIEncoding().GetString(tempConverted);
// get "username"
// get "password"
var usernamePassword = user.Split(new[] { ':' });
var username = usernamePassword[0];
var password = usernamePassword[1];
_log.Debug("Basic Authorizing {0}", username);
Authentificate(username, password);
}
catch (Exception)
{
}
}
return SecurityContext.IsAuthenticated;
}
示例5: ProcessBasicAuthorization
public static bool ProcessBasicAuthorization(HttpContext context, out string authCookie)
{
authCookie = null;
try
{
//Try basic
var authorization = context.Request.Headers["Authorization"];
if (string.IsNullOrEmpty(authorization))
{
return false;
}
authorization = authorization.Trim();
if (authorization.IndexOf("Basic", 0) != 0)
{
return false;
}
// cut the word "basic" and decode from base64
// get "username:password"
var tempConverted = Convert.FromBase64String(authorization.Substring(6));
var user = new ASCIIEncoding().GetString(tempConverted);
// get "username"
// get "password"
var usernamePassword = user.Split(new[] { ':' });
var username = usernamePassword[0];
var password = usernamePassword[1];
var userInfo = CoreContext.UserManager.GetUserByEmail(username);
if (userInfo != null)
{
authCookie = SecurityContext.AuthenticateMe(userInfo.ID.ToString(), password);
}
}
catch (Exception) { }
return SecurityContext.IsAuthenticated;
}
示例6: ProcessBasicAuthRequest
private void ProcessBasicAuthRequest()
{
string authStr = HttpContext.Current.Request.Headers["Authorization"];
if (authStr == null || authStr.Length == 0)
{
// No credentials; anonymous request
DenyAccess();
return;
}
authStr = authStr.Trim();
if (authStr.IndexOf("Basic", 0) != 0)
{
// Don't understand this header...we'll pass it along and
// assume someone else will handle it
DenyAccess();
return;
}
string encodedCredentials = authStr.Substring(6);
byte[] decodedBytes = Convert.FromBase64String(encodedCredentials);
string s = new ASCIIEncoding().GetString(decodedBytes);
string[] userPass = s.Split(new char[] { ':' });
string username = userPass[0];
string password = userPass[1];
UserInfo user = UserController.GetUserByUsernamePassword(
username, password, System.Web.HttpContext.Current.Request.UserHostAddress);
if (user == null)
{
// Invalid credentials; deny access
DenyAccess();
return;
//throw new Exception("Wrong BASIC credentials have been supplied");
}
SecurityContext.SetThreadPrincipal(user);
}
示例7: GetMessage
private string[] GetMessage(NetworkStream stream)
{
byte[] numArray = new byte[4096];
int count = stream.Read(numArray, 0, 4096);
string str = new ASCIIEncoding().GetString(numArray, 0, count).Trim(new char[1]);
Trace.Write(new LogInfo(LogType.Workflow, null, " --> " + str));
return str.Split(new char[1]
{
'|'
}, StringSplitOptions.None);
}
示例8: OnDataReceived
// This the call back function which will be invoked when the socket
// detects any client writing of data on the stream
public void OnDataReceived(IAsyncResult asyn)
{
try
{
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
int iRx = 0;
// Complete the BeginReceive() asynchronous call by EndReceive() method
// which will return the number of characters written to the stream
// by the client
iRx = socketData.m_currentSocket.EndReceive(asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.Default.GetDecoder();
int charLen = d.GetChars(socketData.dataBuffer,
0, iRx, chars, 0);
System.String szData = new System.String(chars);
string incoming = szData.Substring(0, szData.Length - 1);
if (incoming.StartsWith("/rsaC"))
{
#if _SHOWMSG
MessageBox.Show("RSA public key received");
#endif
string rsaKey = incoming.Substring(5);
string[] fields = rsaKey.Split(' ');
clientInfo tempclient = new clientInfo();
tempclient.ip = fields[0];
tempclient.port = fields[1];
tempclient.publicKey = fields[2];
if(!clientsList.Contains(tempclient)) clientsList.Add(tempclient);
}
else if (incoming.StartsWith("/bck"))
{
//client wants to back up
//decide which parties to connect
//pseudo connections list.
string[] backupreq = incoming.Substring(4).Split(' ');
//client req = new client();
int clientnum = -1;
for (int i = 0; i < clientsList.Count; i++)
{
if (clientsList[i].ip.Equals(backupreq[0]))
{
if (clientsList[i].port.Equals(backupreq[1]))
{
clientnum = i;
}
}
}
if (clientnum == -1) MessageBox.Show("Backup Request from unauthenticated user");
else
{
//req = clientsList[clientnum];
clientsList[clientnum].files[0].fileID = backupreq[2];
clientsList[clientnum].files[0].filesize = System.Convert.ToInt32(backupreq[3]);
//first part of every ticket is same
string ticketData = clientsList[clientnum].ip + " " + clientsList[clientnum].port + " " + clientsList[clientnum].publicKey;
// Create a UnicodeEncoder to convert between byte array and string.
ASCIIEncoding ByteConverter = new ASCIIEncoding();
byte[] originalData = ByteConverter.GetBytes(ticketData);
byte[] signedData;
signedData = rsa.SignData(originalData, new SHA1CryptoServiceProvider());
for (int i = 0; i < clientsList.Count; i++)
{
//Ticket i = E(PRas, IPa + PUa) || E(PRas, IPb + PUb)
if (i != clientnum)
{
//second part of the ticket
string ticketSecondData = clientsList[i].ip + " " + clientsList[i].port + " " + clientsList[i].publicKey;
// Create a UnicodeEncoder to convert between byte array and string.
byte[] originalSecondData = ByteConverter.GetBytes(ticketSecondData);
byte[] signedSecondData;
signedSecondData = rsa.SignData(originalSecondData, new SHA1CryptoServiceProvider());
clientsList[clientnum].files[0].filetickets.AddToList(originalData, signedData, originalSecondData, signedSecondData);
}
}
//sends them to the client
try
{
string functionID = "/tck";
string strTickets = clientsList[clientnum].files[0].filetickets.EncodeToString();
//.........这里部分代码省略.........
示例9: GetDecodedAndSplitAuthorizatonHeader
private static string[] GetDecodedAndSplitAuthorizatonHeader(
string AuthHeader)
{
string[] RetVal = new string[2] { string.Empty, string.Empty };
if (AuthHeader != null && AuthHeader.StartsWith("Basic "))
{
try
{
string EncodedString = AuthHeader.Substring(6);
byte[] DecodedBytes = Convert.FromBase64String(EncodedString);
string DecodedString = new ASCIIEncoding().GetString(DecodedBytes);
RetVal = DecodedString.Split(new char[] { ':' });
}
catch
{
}
}
return RetVal;
}
示例10: OnPeerDataReceived
public void OnPeerDataReceived(IAsyncResult asyn)
{
try
{
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
int iRx = 0;
// Complete the BeginReceive() asynchronous call by EndReceive() method
// which will return the number of characters written to the stream
// by the client
iRx = socketData.m_currentSocket.EndReceive(asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.Default.GetDecoder();
int charLen = d.GetChars(socketData.dataBuffer,
0, iRx, chars, 0);
System.String szData = new System.String(chars);
string incoming = szData.Substring(0, szData.Length - 1);
if (incoming.StartsWith("/file"))
{
MessageBox.Show("receiving file");
//recieved file
//file infile = new file();
string infilemsg = incoming.Substring(5);
cryptor.rijn.Key = senderClient.sessionkey;
string infilepart = cryptor.DecryptMessage(infilemsg);
string[] infilefields = infilepart.Split(' ');
//infile.fileid = infilefields[0];
//infile.filesize = infilefields[1];
string concat = infilefields[2]+" "+infilefields[3]+" "+infilefields[4];
byte[] bytefile = System.Text.Encoding.ASCII.GetBytes(concat);
//infile.filedata = bytefile;
string filename = infilefields[0];
//infile.filename = filename;
//filelist.Add(infile);
FileStream fStream = new FileStream(filename, FileMode.CreateNew);
BinaryWriter bw = new BinaryWriter(fStream);
bw.Write(bytefile);
bw.Close();
fStream.Close();
}
else if (incoming.StartsWith("/req"))
{
//MessageBox.Show("Give me a halelujah");
//recieved share request
//receive tickets and import them to a arraylist.
mytickets tickets = new mytickets();
//List<client> clientlist = new List<client>();
tickets.DecodeFromString(incoming.Substring(4));
if ((!rsaserver.VerifyData(tickets.ticketlist[0].origFirst, new SHA1CryptoServiceProvider(), tickets.ticketlist[0].signFirst))
|| (!rsaserver.VerifyData(tickets.ticketlist[0].origSecond, new SHA1CryptoServiceProvider(), tickets.ticketlist[0].signSecond)))
{
MessageBox.Show("AS is not authentic!");
}
else
{
ASCIIEncoding ByteConverter = new ASCIIEncoding();
string originalData = ByteConverter.GetString(tickets.ticketlist[0].origSecond);
string[] origfields = originalData.Split(' ');
if (!rsa.ToXmlString(false).Equals(origfields[2]))
{
MessageBox.Show("This ticket is not mine!");
}
else
{
string destData = ByteConverter.GetString(tickets.ticketlist[0].origFirst);
string[] destfields = destData.Split(' ');
senderClient = new client();
senderClient.ip = destfields[0];
senderClient.port = destfields[1];
senderClient.publicKey = destfields[2];
senderClient.ticket = incoming.Substring(4);
//WaitForPeerData(); // gerek var mý ?
}
}
}
else if (incoming.StartsWith("/key"))
{
//recieved shared key
string[] KeyFields = incoming.Substring(4).Split(' ');
rsapeer.FromXmlString(senderClient.publicKey);
//.........这里部分代码省略.........
示例11: msgLoop
private void msgLoop()
{
while (true)
{
lock (clientLock)
{
byte[] bytes = new byte[1024];
int len = stream.Read(bytes, 0, 1024);
if (len == 0)
{
break;
}
string str = new ASCIIEncoding().GetString(bytes, 0, len);
foreach (string split in str.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
{
OnMsgGet(split);
}
}
}
}
示例12: OnAuthenticateRequest
public void OnAuthenticateRequest(object source, EventArgs eventArgs)
{
HttpApplication app = (HttpApplication)source;
//the Authorization header is checked if present
string authHeader = app.Request.Headers["Authorization"];
if (!string.IsNullOrEmpty(authHeader))
{
string authStr = app.Request.Headers["Authorization"];
if (authStr == null || authStr.Length == 0)
{
// No credentials; anonymous request
return;
}
authStr = authStr.Trim();
if (authStr.IndexOf("Basic", 0) != 0)
{
// header is not correct...we'll pass it along and
// assume someone else will handle it
return;
}
authStr = authStr.Trim();
string encodedCredentials = authStr.Substring(6);
byte[] decodedBytes =
Convert.FromBase64String(encodedCredentials);
string s = new ASCIIEncoding().GetString(decodedBytes);
string[] userPass = s.Split(new char[] { ':' });
string username = userPass[0];
string password = userPass[1];
Microsoft.Xrm.Client.CrmConnection connection = GetCrmConnection(username, password);
using (OrganizationService service = new OrganizationService(connection))
{
WhoAmIRequest req = new WhoAmIRequest();
WhoAmIResponse resp = (WhoAmIResponse)service.Execute(req);
if (resp.Results.Count > 0)
{
app.Context.User = new GenericPrincipal(new GenericIdentity(resp.UserId.ToString()), new string []{"none"});
}
else
{
DenyAccess(app);
return;
}
}
if (Membership.ValidateUser(username, password))
{
string[] roles = Roles.GetRolesForUser(username);
}
else
{
}
}
else
{
app.Response.StatusCode = 401;
app.Response.End();
}
}