本文整理汇总了C#中UTF8Encoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetString方法的具体用法?C# UTF8Encoding.GetString怎么用?C# UTF8Encoding.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.GetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecryptRijndael
public static string DecryptRijndael(string encryptedString)
{
byte[] encrypted;
byte[] fromEncrypted;
UTF8Encoding utf8Converter = new UTF8Encoding();
encrypted = Convert.FromBase64String(encryptedString);
RijndaelManaged myRijndael = new RijndaelManaged();
ICryptoTransform decryptor = myRijndael.CreateDecryptor(Key, IV);
MemoryStream ms = new MemoryStream(encrypted);
CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);
fromEncrypted = new byte[encrypted.Length];
cs.Read(fromEncrypted, 0, fromEncrypted.Length);
string decryptedString = utf8Converter.GetString(fromEncrypted);
int indexNull = decryptedString.IndexOf("\0");
if (indexNull > 0)
{
decryptedString = decryptedString.Substring(0, indexNull);
}
return decryptedString;
}
示例2: RunTest
static bool RunTest (ThreadStart tstart, bool delete)
{
locker = 0;
Thread t = new Thread (tstart);
t.Start ();
using (FileStream fs = File.Open (path, FileMode.Create, FileAccess.Write, FileShare.Delete)) {
Byte [] info = new UTF8Encoding (true).GetBytes ("This is some text in the file.\r\n");
fs.Write (info, 0, info.Length);
fs.Write (info, 0, info.Length);
fs.Write (info, 0, info.Length);
fs.Write (info, 0, info.Length);
fs.Write (info, 0, info.Length);
}
using (FileStream fs = File.Open (path, FileMode.Open, FileAccess.ReadWrite, FileShare.Delete)) {
locker = 1;
byte [] b = new byte [10];
UTF8Encoding temp = new UTF8Encoding (true);
while (fs.Read (b, 0, b.Length) > 0) {
temp.GetString (b);
Thread.Sleep (1000);
}
if (delete && !File.Exists (path))
throw new Exception ("File should continue to exist until FileStream is closed.");
}
t.Join ();
return (!File.Exists (path));
}
示例3: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: ");
try
{
Byte[] bytes = new Byte[] {
85, 84, 70, 56, 32, 69, 110,
99, 111, 100, 105, 110, 103, 32,
69, 120, 97, 109, 112, 108, 101};
UTF8Encoding utf8 = new UTF8Encoding();
string str = utf8.GetString(bytes, 0, bytes.Length);
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例4: NegTest1
public bool NegTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest1: ArgumentNullException is not thrown when bytes is a null reference");
try
{
Byte[] bytes = null;
UTF8Encoding utf8 = new UTF8Encoding();
string str = utf8.GetString(bytes, 0, 2);
TestLibrary.TestFramework.LogError("101.1", "ArgumentNullException is not thrown when bytes is a null reference.");
retVal = false;
}
catch (ArgumentNullException) { }
catch (Exception e)
{
TestLibrary.TestFramework.LogError("101.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例5: Decrypt
// Token: 0x06000EF8 RID: 3832 RVA: 0x00045384 File Offset: 0x00043584
public static string Decrypt(string encrypted)
{
RijndaelManaged rijndaelManaged = new RijndaelManaged();
ICryptoTransform decryptor = rijndaelManaged.CreateDecryptor(SimpleAES.key, SimpleAES.vector);
UTF8Encoding uTF8Encoding = new UTF8Encoding();
return uTF8Encoding.GetString(SimpleAES.Decrypt(Convert.FromBase64String(encrypted), decryptor));
}
示例6: get_uft8
public static string get_uft8(string unicodeString)
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] encodedBytes = utf8.GetBytes(unicodeString);
string decodedString = utf8.GetString(encodedBytes);
return decodedString;
}
示例7: DecryptRSA
public static string DecryptRSA(string privateKeyAsPem, byte[] payload, string passphrase = null)
{
var encoder = new UTF8Encoding();
byte[] byte_payload = payload;
CryptoKey d = CryptoKey.FromPrivateKey(privateKeyAsPem, passphrase);
OpenSSL.Crypto.RSA rsa = d.GetRSA();
byte[] result = rsa.PrivateDecrypt(byte_payload, OpenSSL.Crypto.RSA.Padding.PKCS1);
rsa.Dispose();
return encoder.GetString(result);
}
示例8: PosTest1
public void PosTest1()
{
Byte[] bytes = new Byte[] {
85, 84, 70, 56, 32, 69, 110,
99, 111, 100, 105, 110, 103, 32,
69, 120, 97, 109, 112, 108, 101};
UTF8Encoding utf8 = new UTF8Encoding();
string str = utf8.GetString(bytes, 0, bytes.Length);
}
示例9: NegTest1
public void NegTest1()
{
Byte[] bytes = null;
UTF8Encoding utf8 = new UTF8Encoding();
Assert.Throws<ArgumentNullException>(() =>
{
string str = utf8.GetString(bytes, 0, 2);
});
}
示例10: RunTally
private string RunTally(string input)
{
var encoding = new UTF8Encoding();
using (var inStream = new MemoryStream(encoding.GetBytes(input)))
{
using (var outStream = new MemoryStream())
{
Tournament.Tally(inStream, outStream);
return encoding.GetString(outStream.GetBuffer());
}
}
}
示例11: UTF8ToString
public static string UTF8ToString(MemoryStream ms)
{
var utf = new UTF8Encoding(false);
var result = utf.GetString(
ms.GetBuffer(), 0, (int)ms.Length
);
// Fucking UTF8
if (result[0] == 0xFEFF)
result = result.Substring(1);
return result;
}
示例12: readfile
public void readfile(object obj)
{
Monitor.Enter(this);
FileStream fs = File.OpenRead(@"d:\temp\myfile.txt");
byte [] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while(fs.Read(b, 0, b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
Monitor.Exit(this);
Thread.Sleep(400);
}
示例13: NegTest4
public void NegTest4()
{
Byte[] bytes = new Byte[] {
85, 84, 70, 56, 32, 69, 110,
99, 111, 100, 105, 110, 103, 32,
69, 120, 97, 109, 112, 108, 101};
UTF8Encoding utf8 = new UTF8Encoding();
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
string str = utf8.GetString(bytes, 1, bytes.Length);
});
}
示例14: Start
// Use this for initialization
void Start()
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("127.0.0.1", 10000);
clientStream = tcpClient.GetStream();
byte[] message = new byte[4096];
int bytesRead;
bytesRead = 0;
bytesRead = clientStream.Read(message, 0, 4096);
UTF8Encoding encoder = new UTF8Encoding();
MonoBehaviour.print(encoder.GetString(message, 0, bytesRead));
}
示例15: Install_Click
protected void Install_Click(object sender, EventArgs e)
{
bool success = false;
try
{
switch (_catalogType)
{
case CatalogType.Plugins:
case CatalogType.Widgets:
string fileName = Item.FileName;
if (fileName.EndsWith(".zip"))
fileName = fileName.Replace(".zip", ".dll");
if (!fileName.EndsWith(".dll"))
fileName = fileName + ".dll";
new WebClient().DownloadFile(Item.DownloadUrl, Path.Combine(Server.MapPath("~/bin"), fileName));
break;
case CatalogType.Themes:
string themeFilename = Path.Combine(Server.MapPath("~/files/themes"), Item.FileName);
new WebClient().DownloadFile(Item.DownloadUrl, themeFilename);
UTF8Encoding utf = new UTF8Encoding();
string encodedFile = utf.GetString(File.ReadAllBytes(themeFilename));
ThemeConverter.ToDisk(encodedFile, Server.MapPath("~/files/themes/"), true, Item.Name);
File.Delete(themeFilename);
break;
}
success = true;
}
catch { }
if (success)
{
InstallButton.Enabled = false;
CancelButton.Enabled = false;
Message.Type = StatusType.Success;
Message.Text = string.Format("This {0} has been successfully installed.", _itemTypeName);
}
else
{
InstallButton.Text = "Try Again";
Message.Type = StatusType.Error;
Message.Text = string.Format("An error has occurred during the downloading of this {0}.", _itemTypeName);
}
}