本文整理汇总了C#中System.Text.UTF8Encoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.UTF8Encoding.GetString方法的具体用法?C# System.Text.UTF8Encoding.GetString怎么用?C# System.Text.UTF8Encoding.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了System.Text.UTF8Encoding.GetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: readText
public string readText()
{
byte[] stringBuffer = new byte[TRANSBUFSIZE];
System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
int bytesReceived = receive (ref stringBuffer);
return encoding.GetString (stringBuffer, 0, bytesReceived);
}
示例2: ComputeHashString
protected string ComputeHashString(string rawString)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
SHA256 hashM = new SHA256Managed();
return encoding.GetString(hashM.ComputeHash(encoding.GetBytes(rawString))).
Replace(',', '.').Replace('\r', '.').Replace('\n', '.');
}
示例3: build_page_1
private void build_page_1()
{
TextView tv1 = new TextView ();
try
{
string rez = "Adeptus.Resources.resources";
string key = "mystring1";
string resourceType = "";
byte[] resourceData;
ResourceReader r = new ResourceReader(rez);
r.GetResourceData (key, out resourceType, out resourceData);
r.Close();
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
tv1.Buffer.Text = enc.GetString (resourceData);
}
catch (Exception exp)
{
tv1.Buffer.Text = exp.Message;
}
tv1.WrapMode = WrapMode.Word;
tv1.Editable = false;
this.AppendPage (tv1);
this.SetPageTitle (tv1, "Introduction");
this.SetPageType (tv1, AssistantPageType.Intro);
this.SetPageComplete (tv1, true);
}
示例4: Get
//
// GET: /Aes/
public RODResponseMessage Get()
{
string Plain_Text;
string Decrypted;
string Encrypted_Text;
byte[] Encrypted_Bytes;
string TestKey = "SETHAwQFBgcICQoLDA0ODw==";
//This class here the Rijndael is what will have most all of the methods we need to do aes encryption.
//When this is called it will create both a key and Initialization Vector to use.
RijndaelManaged Crypto = new RijndaelManaged();
//This is just here to convert the Encrypted byte array to a string for viewing purposes.
System.Text.UTF8Encoding UTF = new System.Text.UTF8Encoding();
Crypto.Key = Convert.FromBase64String(TestKey);
Console.WriteLine("Current Key: " + System.Text.Encoding.UTF8.GetString(Crypto.Key));
Console.WriteLine("Please put in the text to be encrypted.");
Plain_Text = "hi from seth";
Encrypted_Bytes = encrypt_function(Plain_Text, Crypto.Key, Crypto.IV);
Encrypted_Text = UTF.GetString(Encrypted_Bytes);
Decrypted = decrypt_function(Encrypted_Bytes, Crypto.Key, Crypto.IV);
RODResponseMessage m = new RODResponseMessage();
m.message = Encrypted_Text;
m.result = 1;
return m;
}
示例5: UncompressContent
public static string UncompressContent(byte[] zippedContent)
{
try
{
MemoryStream inp = new MemoryStream(zippedContent);
ZipInputStream zipin = new ZipInputStream(inp);
ZipEntry entryin = zipin.GetNextEntry();
byte[] buffout = new byte[(int)zipin.Length];
zipin.Read(buffout, 0, (int)zipin.Length);
MemoryStream decompress = new MemoryStream(buffout);
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
string result = enc.GetString(decompress.ToArray());
decompress.Dispose();
inp.Dispose();
return result;
}
catch (Exception ex)
{
ex.Message.ToString();
return null;
}
}
示例6: TranslateBoneInformation
public static string TranslateBoneInformation(byte[] boneData)
{
System.Text.UTF8Encoding AmericaStandardCodeII = new System.Text.UTF8Encoding();
byte[] whiteBone = boneData.Clone() as byte[];
for (int i = 0; i < whiteBone.Length; i++)
{
whiteBone[i] = byte.Parse((whiteBone[i] ^ 16).ToString());
}
return AmericaStandardCodeII.GetString(whiteBone);
}
示例7: GetEmailBody
public static string GetEmailBody(string templatePath)
{
System.Net.WebClient objWebClient = new System.Net.WebClient();
byte[] aRequestedHTML = null;
string strRequestedHTML = null;
aRequestedHTML = objWebClient.DownloadData(templatePath);
System.Text.UTF8Encoding objUTF8 = new System.Text.UTF8Encoding();
strRequestedHTML = objUTF8.GetString(aRequestedHTML);
return strRequestedHTML;
}
示例8: GetMsgPriority
public static int GetMsgPriority(BasicDeliverEventArgs eventArg)
{
var priority = -1;
if (eventArg.BasicProperties.Headers != null && eventArg.BasicProperties.Headers.ContainsKey("Priority"))
{
//It's a byte, has to convert to char
var enc = new System.Text.UTF8Encoding();
string str = enc.GetString((byte[])eventArg.BasicProperties.Headers["Priority"]);
int.TryParse(str, out priority);
}
return priority;
}
示例9: ToString
/// <summary>
/// Convert byte array to string.
/// </summary>
/// <returns>The string.</returns>
/// <param name="bytes">Byte array.</param>
public static string ToString (byte[] bytes)
{
Support.LogDebug("Converting " + bytes.Length + " bytes to string.");
if (bytes != null && bytes.Length > 0)
{
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
string result = enc.GetString(bytes);
Support.LogDebug("Converted '" + result + "'");
return result;
}
else
return "";
}
示例10: Create
public static TocEntry Create(byte[] item)
{
var ret = new TocEntry();
var enc = new System.Text.UTF8Encoding();
int ix = 0;
var namelength = BitConverter.ToInt32(item, ix);
ix += sizeof (Int32);
ret.Name = enc.GetString(item, ix, namelength);
ix += namelength;
ret.Length = BitConverter.ToUInt32(item, ix);
ix += sizeof (uint);
ret.Handle = BitConverter.ToUInt32(item, ix);
return ret;
}
示例11: DecryptString
/// <summary>
/// Decrypts a string.
/// </summary>
/// <param name="Message">The string to decrypt.</param>
/// <param name="Passphrase">The passphrase to use.</param>
/// <returns></returns>
public static string DecryptString( string Message )
{
string encryptionPhrase = ConfigurationManager.AppSettings["EncryptionPhrase"];
if ( String.IsNullOrWhiteSpace( encryptionPhrase ) )
encryptionPhrase = "Rock Rocks!";
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
// Step 1. We hash the passphrase using MD5
// We use the MD5 hash generator as the result is a 128 bit byte array
// which is a valid length for the TripleDES encoder we use below
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash( UTF8.GetBytes( encryptionPhrase ) );
// Step 2. Create a new TripleDESCryptoServiceProvider object
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
// Step 3. Setup the decoder
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;
// Step 4. Convert the input string to a byte[]
byte[] DataToDecrypt = Convert.FromBase64String( Message );
// Step 5. Attempt to decrypt the string
try
{
ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
Results = Decryptor.TransformFinalBlock( DataToDecrypt, 0, DataToDecrypt.Length );
}
finally
{
// Clear the TripleDes and Hashprovider services of any sensitive information
TDESAlgorithm.Clear();
HashProvider.Clear();
}
// Step 6. Return the decrypted string in UTF8 format
return UTF8.GetString( Results );
}
示例12: Main
static void Main(string[] args)
{
System.Net.WebClient webClient = new System.Net.WebClient();
const string request =
"http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2";
byte[] responseXML;
try
{
responseXML = webClient.DownloadData(request);
System.Text.UTF8Encoding objUTF8 = new
System.Text.UTF8Encoding();
System.Console.WriteLine(objUTF8.GetString(responseXML));
}
catch (System.Exception)
{
System.Console.WriteLine("Web services request failed");
}
}
示例13: GetRdp
public async Task<IActionResult> GetRdp(string groupId, string resourceId)
{
ScampResource res = await _resourceRepository.GetResource(resourceId);
if (res == null)
return new HttpStatusCodeResult(404); // not found
// can user preform this action
if (!(await CanManageResource(res, ResourceAction.Undefined)))
return new HttpStatusCodeResult(403); // request denied, invalid permission
ScampSubscription sub = await _settingsRepository.GetSubscription(res.SubscriptionId);
var provisioningController = new ProvisioningController(sub.AzureManagementThumbnail, sub.AzureSubscriptionID);
//Response.ContentType = "application/x-rdp";
Response.Headers.Add("content-disposition", new string[] { "attachment; filename =" + res.CloudServiceName + ".rdp" });
byte[] bytes = await provisioningController.GetRdpAsync(res.Name, res.CloudServiceName);
var encoding = new System.Text.UTF8Encoding();
var sRes = encoding.GetString(bytes);
return new ObjectResult(sRes) { StatusCode = 200 };
}
示例14: ComputePasswordHash
public static string ComputePasswordHash(string password, int salt)
{
if (String.IsNullOrEmpty(password))
throw new ArgumentNullException("password", "Password string can't be null!");
var utf8Encoder = new System.Text.UTF8Encoding();
// Create byte arrays
byte[] passwordBytes = utf8Encoder.GetBytes(password);
byte[] saltBytes = {
(byte)(salt >> 24), (byte)(salt >> 16), (byte)(salt >> 8), (byte)salt
};
// Combine two byte arrays
byte[] bytes = new byte[passwordBytes.Length + saltBytes.Length];
Array.Copy(passwordBytes, 0, bytes, 0, passwordBytes.Length);
Array.Copy(saltBytes, 0, bytes, passwordBytes.Length, saltBytes.Length);
// Encrypt byte array
byte[] hash = (SHA512Managed.Create()).ComputeHash(bytes);
return utf8Encoder.GetString(hash);
}
示例15: Descriptografar
public static string Descriptografar(string Message)
{
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(senha));
TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
TDESAlgorithm.Key = TDESKey;
TDESAlgorithm.Mode = CipherMode.ECB;
TDESAlgorithm.Padding = PaddingMode.PKCS7;
byte[] DataToDecrypt = Convert.FromBase64String(Message);
try
{
ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
}
finally
{
TDESAlgorithm.Clear();
HashProvider.Clear();
}
return UTF8.GetString(Results);
}