本文整理汇总了C#中System.Text.UnicodeEncoding.GetByteCount方法的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding.GetByteCount方法的具体用法?C# UnicodeEncoding.GetByteCount怎么用?C# UnicodeEncoding.GetByteCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UnicodeEncoding
的用法示例。
在下文中一共展示了UnicodeEncoding.GetByteCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Stopwatch start = Stopwatch.StartNew();
FileStream fs;
UnicodeEncoding uni = new UnicodeEncoding();
//string stime = "";
fs = new FileStream("./solution3.log", FileMode.Create);
// for (int j = 1; j <= 50; j++)
// {
//int totalReset = 0;
for (int i = 0; i < 50; i++)
{
start.Restart();
Solver s = new Solver(3, @"C:\ULAVAL\IFT-4102\TP1\Question2\sudoku\base.txt", 810, 0.5, 0.8);
string solution = s.Solve();
//totalReset += reset;
start.Stop();
string stime = "Temps : " + start.ElapsedMilliseconds + "ms" + Environment.NewLine + solution + Environment.NewLine;
Console.Write(stime);// + solution );
fs.Write(uni.GetBytes(stime), 0, uni.GetByteCount(stime));
// }
// long total = start.ElapsedMilliseconds;
// string timeTotal = total + "ms";
// string timeMoyen = (total / 20.0) + "ms";
// //stime = "With comparaison : " + (1 - 0.02 * j) + " took a total of " + timeTotal + " Moyen : " + timeMoyen + " and moyenReset " + totalReset / 20 + Environment.NewLine;
// Console.Write(stime);
//fs.Write(uni.GetBytes(stime), 0, uni.GetByteCount(stime));
}
}
示例2: PosTest1
public void PosTest1()
{
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
actualValue = uEncoding.GetByteCount("");
Assert.Equal(0, actualValue);
}
示例3: HashPassword
public static string HashPassword(string password, string saltValue)
{
if (String.IsNullOrEmpty(password)) throw new ArgumentException("Password is null");
var encoding = new UnicodeEncoding();
var hash = new SHA256CryptoServiceProvider();
if (saltValue == null)
{
saltValue = GenerateSaltValue();
}
byte[] binarySaltValue = Convert.FromBase64String(saltValue);
byte[] valueToHash = new byte[SaltValueSize + encoding.GetByteCount(password)];
byte[] binaryPassword = encoding.GetBytes(password);
binarySaltValue.CopyTo(valueToHash, 0);
binaryPassword.CopyTo(valueToHash, SaltValueSize);
byte[] hashValue = hash.ComputeHash(valueToHash);
var hashedPassword = String.Empty;
foreach (byte hexdigit in hashValue)
{
hashedPassword += hexdigit.ToString("X2", CultureInfo.InvariantCulture.NumberFormat);
}
return hashedPassword;
}
示例4: PosTest3
public void PosTest3()
{
String str = GetString(1);
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
actualValue = uEncoding.GetByteCount(str);
Assert.Equal(2, actualValue);
}
示例5: PosTest1
public void PosTest1()
{
Char[] chars = new Char[] { };
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
actualValue = uEncoding.GetByteCount(chars, 0, 0);
Assert.Equal(0, actualValue);
}
示例6: PosTest3
public void PosTest3()
{
Char[] chars = GetCharArray(1);
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
actualValue = uEncoding.GetByteCount(chars, 0, 1);
Assert.Equal(2, actualValue);
}
示例7: NegTest1
public void NegTest1()
{
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
Assert.Throws<ArgumentNullException>(() =>
{
actualValue = uEncoding.GetByteCount(null, 0, 0);
});
}
示例8: TestMailSlot
public static void TestMailSlot()
{
//int i = 0;
MailSlotTransport transport = new MailSlotTransport();
//StringBuilder sb = new StringBuilder();
//while (true)
//{
// if (transport.Ready)
// {
// sb.Append("|" + sb.Length);
// bool retval = transport.Send("csharp.test.mailslot:1|c|" + sb.ToString());
// Console.WriteLine("return " + retval);
// }
//}
string SLOTNAME = @"\\.\mailslot\afcollectorapi";
SafeFileHandle slotHandle = NativeMailSlot.CreateFile(SLOTNAME,
(uint)FileAccess.Write,
(uint)FileShare.ReadWrite,
0,
(uint)FileMode.Open,
(uint)FileAttributes.Normal,
0);
FileStream fs = new FileStream(slotHandle, FileAccess.Write);
UnicodeEncoding encoding = new UnicodeEncoding();
string data_string = string.Format("{0}:{1}:{2}", Process.GetCurrentProcess().Id, 3, "csharp.test.mailslot:1|c");
byte[] data_bytes = encoding.GetBytes(data_string);
int byteCount = encoding.GetByteCount(data_string);
fs.Write(data_bytes, 0, byteCount);
fs.Flush();
int size = 0, nextsize = 0, count = 0, timeout = 0;
bool succeeded = false;
if (slotHandle.IsInvalid)
{
Console.WriteLine("MailSlot handle is invalid");
return;
}
try
{
succeeded = NativeMailSlot.GetMailslotInfo(slotHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
if (succeeded)
{
Console.WriteLine(String.Format("size {0}, nextsize {1}, count {2}, timeout {3}",
size, nextsize, count, timeout));
}
else
{
Console.WriteLine(String.Format("can't get mailslot info {0:d}", Marshal.GetLastWin32Error()));
}
}
示例9: PosTest2
public void PosTest2()
{
String str = GetString(10);
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
String temp = ToString(str);
actualValue = uEncoding.GetByteCount(str);
Assert.Equal(20, actualValue);
}
示例10: NegTest3
public void NegTest3()
{
Char[] chars = GetCharArray(10);
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
actualValue = uEncoding.GetByteCount(chars, 5, -1);
});
}
示例11: GetCrc
internal static uint GetCrc(string sResult)
{
UnicodeEncoding enc = new UnicodeEncoding();
int iCount = enc.GetByteCount(sResult);
using (CrcStream crc = new CrcStream(iCount))
{
crc.Write(enc.GetBytes(sResult), 0, iCount);
return crc.WriteCrc;
// Closed in the Dispose of 'crc'.
}
}
示例12: HashPassword
private static string HashPassword(string clearData, string saltValue, HashAlgorithm hash)
{
UnicodeEncoding encoding = new UnicodeEncoding();
if (clearData != null && hash != null && encoding != null)
{
// If the salt string is null or the length is invalid then
// create a new valid salt value.
if (saltValue == null)
{
// Generate a salt string.
saltValue = GenerateSaltValue();
}
// Convert the salt string and the password string to a single
// array of bytes. Note that the password string is Unicode and
// therefore may or may not have a zero in every other byte.
byte[] binarySaltValue = new byte[SaltValueSize];
binarySaltValue[0] = byte.Parse(saltValue.Substring(0, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);
binarySaltValue[1] = byte.Parse(saltValue.Substring(2, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);
binarySaltValue[2] = byte.Parse(saltValue.Substring(4, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);
binarySaltValue[3] = byte.Parse(saltValue.Substring(6, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);
byte[] valueToHash = new byte[SaltValueSize + encoding.GetByteCount(clearData)];
byte[] binaryPassword = encoding.GetBytes(clearData);
// Copy the salt value and the password to the hash buffer.
binarySaltValue.CopyTo(valueToHash, 0);
binaryPassword.CopyTo(valueToHash, SaltValueSize);
byte[] hashValue = hash.ComputeHash(valueToHash);
// The hashed password is the salt plus the hash value (as a string).
string hashedPassword = saltValue;
foreach (byte hexdigit in hashValue)
{
hashedPassword += hexdigit.ToString("X2", CultureInfo.InvariantCulture.NumberFormat);
}
// Return the hashed password as a string.
return hashedPassword;
}
return null;
}
示例13: HashPassword
/// <summary>
/// Encodes the password using the <see cref="SHA256Managed"/> <see cref="HashAlgorithm"/>.
/// </summary>
/// <param name="password">The password.</param>
/// <param name="saltValue">The salt value. Null if no salt value.</param>
/// <returns>The Base64 encoding <see cref="String"/> of the hashed password.</returns>
public static string HashPassword(string password, string saltValue = null)
{
var encoding = new UnicodeEncoding();
var builder = new StringBuilder();
var salt = saltValue == null ? GenerateSalt() : GetSaltFromString(saltValue);
var dataBuffer = new byte[encoding.GetByteCount(password) + SaltValueSize];
var stringToHashBytes = encoding.GetBytes(password);
salt.CopyTo(dataBuffer, 0);
stringToHashBytes.CopyTo(dataBuffer, SaltValueSize);
HashAlgorithm hashAlgorithm = new SHA256Managed();
var hashedBytes = hashAlgorithm.ComputeHash(dataBuffer);
foreach (var outputByte in salt) builder.Append(outputByte.ToString("x2").ToUpper());
foreach (var outputByte in hashedBytes) builder.Append(outputByte.ToString("x2").ToUpper());
return builder.ToString();
}
示例14: setCharacterComplement
public bool setCharacterComplement( string sCharacterComplement )
{
bool bResult = true;
UnicodeEncoding ue = new UnicodeEncoding();
if( ue.GetByteCount( sCharacterComplement ) != 8 )
{
bResult = false;
throw new ArrayTypeMismatchException( "CharacterComplement should have a length of 8 characters." );
}
m_CharacterComplement = ue.GetBytes( sCharacterComplement );
return bResult;
}
示例15: Send
public bool Send(string mail)
{
try
{
UnicodeEncoding encoding = new UnicodeEncoding();
string data_string = string.Format("{0}:{1}:{2}", Process.GetCurrentProcess().Id, 3, mail);
byte[] data_bytes = encoding.GetBytes(data_string);
int byteCount = encoding.GetByteCount(data_string);
mailSlot.Write(data_bytes, 0, byteCount);
mailSlot.Flush();
Debug.WriteLine("sending " + data_string);
}
catch (IOException ioe)
{
Debug.WriteLine(String.Format("{0} Exception caught.", ioe));
}
return true;
}