本文整理汇总了C#中System.Text.UTF32Encoding.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# UTF32Encoding.GetBytes方法的具体用法?C# UTF32Encoding.GetBytes怎么用?C# UTF32Encoding.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF32Encoding
的用法示例。
在下文中一共展示了UTF32Encoding.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUtf32
public static string GetUtf32(string unicodeString)
{
var utf8 = new UTF32Encoding();
byte[] encodeBytes = utf8.GetBytes(unicodeString);
string decodedString = utf8.GetString(encodeBytes);
return decodedString;
}
示例2: button2_Click
private void button2_Click(object sender, EventArgs e)
{
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
UTF32Encoding utf8 = new UTF32Encoding();
string hashResult = BitConverter.ToString(sha1.ComputeHash(utf8.GetBytes(textBox2.Text)));
label4.Text = hashResult;
label3.Text = hashResult.Length.ToString();
}
示例3: button1_Click
private void button1_Click(object sender, EventArgs e)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
UTF32Encoding utf8 = new UTF32Encoding();
string hashResult = BitConverter.ToString(md5.ComputeHash(utf8.GetBytes(textBox1.Text)));
label1.Text = hashResult;
label2.Text = hashResult.Length.ToString();
}
示例4: Md5Encrypte
public static string Md5Encrypte(string inputString)
{
var u = new System.Text.UTF32Encoding();
byte[] bytes = u.GetBytes(inputString);
System.Security.Cryptography.MD5 md = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] result = md.ComputeHash(bytes);
return Convert.ToBase64String(result);
}
示例5: FromString
/// <summary>hashing from string. Result in format of 000-000</summary>
public static string FromString(string input)
{
if (input.IsNullOrEmpty())
return FromBuffer(null);
var utf32 = new UTF32Encoding();
return FromBuffer(utf32.GetBytes(input));
}
示例6: CreateHash
/// <summary>
/// Creates a password hash from the details provided
/// </summary>
/// <param name="created">The time when the person was created</param>
/// <param name="password">The desired password</param>
/// <param name="salt">The login's salt</param>
/// <returns>A Byte[] with the password hash</returns>
public Byte[] CreateHash(DateTime created, string password, string salt)
{
if (password == null) throw new ArgumentNullException("password");
if (salt == null) throw new ArgumentNullException("salt");
SHA1 sha = new SHA1CryptoServiceProvider();
UTF32Encoding enc = new UTF32Encoding();
var stringValue = string.Concat(_configurationManager.HashConstant, created, password, salt);
return sha.ComputeHash(enc.GetBytes(stringValue));
}
示例7: ComputeSaltedHash
/// <summary>
/// Compute the salted hash of the given password
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
public string ComputeSaltedHash(string password)
{
if (password == null)
throw new ArgumentNullException("password");
//Encoder for password (text->bytes)
UTF32Encoding encoder = new UTF32Encoding();
//Put password bytes and then saly bytes into byte array
var toHash = encoder.GetBytes(password)
.Concat(BitConverter.GetBytes(Salt))
.ToArray();
// Hash the salted password
using (SHA512Managed sha1 = new SHA512Managed())
return BitConverter.ToString(sha1.ComputeHash(toHash)).Replace("-", "");
}
示例8: CharCode
//Used to mimic the charCodeAt Javascript method
static String CharCode(char chr)
{
UTF32Encoding encoding = new UTF32Encoding();
byte[] bytes = encoding.GetBytes(chr.ToString().ToCharArray());
return BitConverter.ToInt32(bytes, 0).ToString();
}
示例9: EncodeBase64
private string EncodeBase64(string strValue)
{
try
{
System.Text.UTF32Encoding objUTF32 = new System.Text.UTF32Encoding();
byte[] objbytes = objUTF32.GetBytes(strValue);
return Convert.ToBase64String(objbytes);
}
catch (Exception ex)
{
VMuktiHelper.ExceptionHandler(ex, "EncodeBase64()", "bootStrapServiceDomain.cs");
return null;
}
}
示例10: NewPwChange_Click
protected void NewPwChange_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(oldPw.Text))
{
oldPwStatus.ForeColor = System.Drawing.Color.Red;
oldPwStatus.Text = "Old Password is required";
}
if (string.IsNullOrEmpty(newPw.Text))
{
newPwStatus.ForeColor = System.Drawing.Color.Red;
newPwStatus.Text = "New Password is required";
}
if (string.IsNullOrEmpty(newPw2.Text))
{
newPw2Status.ForeColor = System.Drawing.Color.Red;
newPw2Status.Text = "Repeat Password is required";
}
if (!string.IsNullOrEmpty(newPw.Text) && !string.IsNullOrEmpty(newPw2.Text))
{
int result = (string.Compare(newPw.Text, newPw2.Text));
if (result == -1)
{
ChangePwStatus.ForeColor = System.Drawing.Color.Red;
ChangePwStatus.Text = "Repeat Password not match with New Password";
}
else if (!string.IsNullOrEmpty(oldPw.Text))
{
SqlConnection sqlConn = new SqlConnection(Shared.SqlConnString);
using (sqlConn)
{
try
{
SqlCommand checkoldpassword = new SqlCommand("SELECT * FROM dbo.[User] WHERE UserID = @userid AND Password = @password", sqlConn);
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
Byte[] hashedBytes;
UTF32Encoding encoder = new UTF32Encoding();
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(newPw.Text));
checkoldpassword.Parameters.AddWithValue("@userid", Session["UserID"].ToString());
checkoldpassword.Parameters.AddWithValue("@password", hashedBytes);
sqlConn.Open();
SqlDataReader reader = checkoldpassword.ExecuteReader();
if (!reader.HasRows)
{
ChangePwStatus.ForeColor = System.Drawing.Color.Red;
ChangePwStatus.Text = "Incorrect old password";
}
else
{
SqlConnection sqlConn2 = new SqlConnection(Shared.SqlConnString);
using (sqlConn2)
{
try
{
SqlCommand changepw = new SqlCommand("UPDATE dbo.[User] SET Password = @password WHERE UserID = @userid", sqlConn2);
changepw.Parameters.AddWithValue("@userid", Session["UserID"].ToString());
changepw.Parameters.AddWithValue("@password", hashedBytes);
sqlConn2.Open();
changepw.ExecuteNonQuery();
}
catch
{
}
}
}
}
catch
{
}
}
}
}
}
示例11: TestUtf32PtrToString
public void TestUtf32PtrToString ()
{
var utf32NativeEndianNoBom = new UTF32Encoding(
bigEndian: !BitConverter.IsLittleEndian,
byteOrderMark: false,
throwOnInvalidCharacters: true
);
// assemble a buffer that contains:
// 1. eight garbage bytes
// 2. the native-endian UTF-32 string "Hello, World" without BOM
// 3. four 0 bytes (as a C wide string terminator)
// 4. the native-endian UTF-32 string "broken" without BOM
// 5. eight 0 bytes
// 6. four garbage bytes
var buf = new List<byte>();
for (int i = 0; i < 2; ++i) {
buf.Add((byte)0x12);
buf.Add((byte)0x34);
buf.Add((byte)0x56);
buf.Add((byte)0x78);
}
buf.AddRange(utf32NativeEndianNoBom.GetBytes("Hello, World"));
for (int i = 0; i < 4; ++i) {
buf.Add((byte)0x00);
}
buf.AddRange(utf32NativeEndianNoBom.GetBytes("broken"));
for (int i = 0; i < 8; ++i) {
buf.Add((byte)0x00);
}
buf.Add((byte)0x12);
buf.Add((byte)0x34);
buf.Add((byte)0x56);
buf.Add((byte)0x78);
// get the array version of this
var bufArr = buf.ToArray();
// allocate a buffer that will contain this string
IntPtr bufPtr = UnixMarshal.AllocHeap(bufArr.Length);
string returned;
try
{
// copy it in
Marshal.Copy(bufArr, 0, bufPtr, bufArr.Length);
// try getting it back
returned = UnixMarshal.PtrToString(bufPtr + 8, utf32NativeEndianNoBom);
}
finally
{
UnixMarshal.FreeHeap(bufPtr);
}
Assert.AreEqual("Hello, World", returned);
}
示例12: EncryptPasswordMD5
public string EncryptPasswordMD5(string Password)
{
try
{
UTF32Encoding u = new UTF32Encoding();
byte[] bytes = u.GetBytes(Password);
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
byte[] strmd5 = MD5.ComputeHash(bytes);
byte[] strSHA1 = u.GetBytes(Convert.ToBase64String(strmd5));
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
byte[] kq = sha1.ComputeHash(strSHA1);
return Convert.ToBase64String(kq);
}
catch
{
return "";
}
}
示例13: btnCreateUser_Click
protected void btnCreateUser_Click(object sender, EventArgs e)
{
// Shared.SqlConnString is obtained from Assets/Shared.cs file
// At beginning of source code, add using statement "using KeysightMOR.Assets"
bool checkselectdiv = false;
foreach (GridViewRow row in DivisionList.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox SelectDivision = (row.Cells[0].FindControl("SelectDivision") as CheckBox);
if (SelectDivision.Checked)
{
checkselectdiv = true;
}
}
}
lblAddUserStatus.Text = null;
if (Position.Text == "Employee" && checkselectdiv == false)
{
lblAddUserStatus.Text = "Please select at least 1 division";
}
SqlConnection sqlConn = new SqlConnection(Shared.SqlConnString);
using (sqlConn)
{
try
{
SqlCommand CheckEmail = new SqlCommand("SELECT * FROM dbo.[User] WHERE UserEmail = @UserEmail AND Status = 1", sqlConn);
CheckEmail.Parameters.AddWithValue("@UserEmail", usrEmail.Text);
sqlConn.Open();
SqlDataReader reader = CheckEmail.ExecuteReader();
EmailExist.Text = null;
if (reader.HasRows)
{
EmailExist.Text = "This email exists. Use another email";
}
else
{
string SqlAddUserCmd;
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
Byte[] hashedBytes;
UTF32Encoding encoder = new UTF32Encoding();
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes("123456789"));
SqlAddUserCmd = "INSERT INTO dbo.[User](UserName, UserEmail, Password, Position, Status) VALUES (@UserName, @UserEmail, @Password, @Position, 1)";
SqlConnection sqlConn2 = new SqlConnection(Shared.SqlConnString);
SqlCommand sqlCmd = new SqlCommand(SqlAddUserCmd, sqlConn2);
sqlCmd.Parameters.AddWithValue("@UserName", usrName.Text);
sqlCmd.Parameters.AddWithValue("@UserEmail", usrEmail.Text);
sqlCmd.Parameters.AddWithValue("@Password", hashedBytes);
sqlCmd.Parameters.AddWithValue("@Position", Position.Text);
using (sqlConn2)
{
try
{
if (!string.IsNullOrEmpty(usrName.Text) && !string.IsNullOrEmpty(usrEmail.Text) && ((Position.Text == "Employee" && checkselectdiv == true) || Position.Text == "Admin"))
{
sqlConn2.Open();
sqlCmd.ExecuteNonQuery();
if (Position.Text == "Employee" && checkselectdiv == true)
{
SqlConnection sqlConn3 = new SqlConnection(Shared.SqlConnString);
string userid = "";
using (sqlConn3)
{
try
{
//if (!string.IsNullOrEmpty(txtAddCm.Text))
//{
SqlCommand getUserIDCmd = new SqlCommand("SELECT UserID FROM dbo.[User] WHERE UserEmail = @UserEmail", sqlConn3);
getUserIDCmd.Parameters.AddWithValue("@UserEmail", usrEmail.Text);
sqlConn3.Open();
SqlDataReader reader1 = getUserIDCmd.ExecuteReader();
if (reader1.HasRows)
{
while (reader1.Read())
{
Console.WriteLine(String.Format("{0}", reader1[0]));
userid = reader1[0].ToString();
}
}
else
{
Console.WriteLine("No rows found.");
}
reader1.Close();
}
//}
catch (Exception ex)
//.........这里部分代码省略.........
示例14: Encrypte
public static string Encrypte(string pString)
{
UTF32Encoding u = new UTF32Encoding();
byte[] bytes = u.GetBytes(pString); //get original string
MD5 md = new MD5CryptoServiceProvider(); // using md5 algorithm
byte[] result = md.ComputeHash(bytes); // encrypted input bytes into encrypted bytes
return Convert.ToBase64String(result); //return encrypted string
}
示例15: UniversalStringEncode
/// <summary>
/// Provides encoding functionality in UniversalString way for a string.
/// </summary>
/// <param name="str"></param>
/// <returns>The encoding result, in byte array form, big endian.</returns>
private static byte[] UniversalStringEncode(string str)
{
UTF32Encoding be = new UTF32Encoding(true, false);
return be.GetBytes(str);
}