public string SaveLicense(string xml, string licenseNamespace) { if (string.IsNullOrWhiteSpace(xml)) { throw new ArgumentNullException(); } byte[] xmlBytes = convertToByteArray(xml); SoapHexBinary shb = new SoapHexBinary(Compression.Compress(xmlBytes)); string xmlHex = null; xmlHex = shb.ToString(); string code = b1DAO.ExecuteSqlForObject <string>(string.Format(this.GetSQL("GetLicenseCode.sql"), licenseNamespace)); b1DAO.ExecuteStatement(string.Format(this.GetSQL("DeleteLicense.sql"), code)); b1DAO.ExecuteStatement(string.Format(this.GetSQL("DeleteLicenseHeader.sql"), code)); code = b1DAO.GetNextCode("DOVER_LICENSE"); b1DAO.ExecuteStatement(string.Format(this.GetSQL("InsertLicenseHeader.sql"), code, licenseNamespace)); InsertAsmBin(xmlHex, code); return(code); }
public static async Task HandleIncomingConnections() { bool runServer = true; // While a user hasn't visited the `shutdown` url, keep on handling requests while (runServer) { HttpListenerContext ctx = await listener.GetContextAsync(); HttpListenerRequest req = ctx.Request; HttpListenerResponse resp = ctx.Response; string providedSignature = req.Headers.Get("X-Lapin-Signature"); byte[] providedSignatureBytes = SoapHexBinary.Parse(providedSignature).Value; byte[] signature = Sign(key, req.InputStream); bool signatureOk = providedSignatureBytes.SequenceEqual(signature); byte[] data = Encoding.UTF8.GetBytes("{\"signature\": " + (signatureOk ? "true" : "false") + "}"); resp.ContentType = "text/json"; resp.ContentEncoding = Encoding.UTF8; resp.ContentLength64 = data.LongLength; await resp.OutputStream.WriteAsync(data, 0, data.Length); resp.Close(); } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var bytes = (byte[])value; var hex = new SoapHexBinary(bytes); writer.WriteValue(hex.ToString()); }
private static readonly Regex asciiPattern = new Regex("^[\x20-\x7F]{32}$", RegexOptions.Compiled); // Pattern for string in ASCII code (alphanumeric symbols) private void ParseCID(string cid) { if (String.IsNullOrWhiteSpace(cid) || !asciiPattern.IsMatch(cid)) { return; } var bytes = SoapHexBinary.Parse(cid).Value; _manufacturerID = bytes[0]; // Bytes 0 _oemApplicationID = Encoding.ASCII.GetString(bytes.Skip(1).Take(2).ToArray()); // Bytes 1-2 _productName = Encoding.ASCII.GetString(bytes.Skip(3).Take(5).ToArray()); // Bytes 3-7 var productRevisionBits = new BitArray(new[] { bytes[8] }).Cast <bool>().Reverse().ToArray(); // Bytes 8 var major = ConvertFromBitsToInt(productRevisionBits.Take(4).Reverse()); var minor = ConvertFromBitsToInt(productRevisionBits.Skip(4).Take(4).Reverse()); _productRevision = String.Format("{0}.{1}", major, minor); _productSerialNumber = BitConverter.ToUInt32(bytes, 9); // Bytes 9-12 var manufacturingDateBits = bytes.Skip(13).Take(2) // Bytes 13-14 .SelectMany(x => new BitArray(new[] { x }).Cast <bool>().Reverse()) .Skip(4) // Skip reserved field. .ToArray(); var year = ConvertFromBitsToInt(manufacturingDateBits.Take(8).Reverse()); var month = ConvertFromBitsToInt(manufacturingDateBits.Skip(8).Take(4).Reverse()); if ((year <= 1000) && (month <= 12)) { _manufacturingDate = new DateTime(year + 2000, month, 1); } }
private void ParseHexBinary(XsdtType x) { SoapHexBinary hb = SoapHexBinary.Parse(x.ValuePart); x.NetValue = hb.Value; x.NetType = x.NetValue.GetType(); }
public bool LoginCheck(string username, string password) { if (!username.All(char.IsLetterOrDigit)) { return(false); } var account = Program.EODatabase.Query <CharacterRecord>($"SELECT name, account FROM `characters` WHERE name = '{username}'"); if (account == null || !account.Any()) { return(false); } var hash = new List <byte>(); hash.AddRange((Encoding.ASCII.GetBytes("ChangeMe"))); hash.AddRange((Encoding.ASCII.GetBytes(account[0].Account))); hash.AddRange((Encoding.ASCII.GetBytes(password))); var computed = new SoapHexBinary(SHA256.Create().ComputeHash(hash.ToArray())).ToString().Replace("-", "").Replace(" ", "").ToLower(); var result = Program.EODatabase.Query <AccountRecord>($"SELECT username FROM `accounts` WHERE `username` = '{account[0].Account}' AND `password` = '{computed}'"); if (result == null || !result.Any()) { return(false); } return(true); }
public static void Main(string[] args) { if (args.Length < 3 || !File.Exists(args[1])) { Console.WriteLine("b2hex -(bh/hb) input output"); return; } byte[] file_in = File.ReadAllBytes(args[1]); FileStream file_out = new FileStream(args[2], FileMode.Create); if (args[0].Equals("-hb")) { SoapHexBinary shb = SoapHexBinary.Parse(Encoding.ASCII.GetString(file_in, 0, file_in.Length)); file_out.Write(shb.Value, 0, shb.Value.Length); } else { SoapHexBinary shb = new SoapHexBinary(file_in); byte[] utf16Bytes = Encoding.Unicode.GetBytes(shb.ToString()); byte[] bytes = Encoding.Convert(Encoding.Unicode, Encoding.ASCII, utf16Bytes); file_out.Write(bytes, 0, bytes.Length); } file_out.Close(); return; }
/// <summary> /// /// </summary> /// <param name="Data"></param> /// <returns></returns> public static string ConvertBytesToString(byte[] Data) { SoapHexBinary SH = new SoapHexBinary(Data); //byte[,] item = new byte[4, 4]; return(SH.ToString()); }
public byte [] HexDecode(String HexString) { HexString = HexString.Replace("@", ""); SoapHexBinary converter = SoapHexBinary.Parse(HexString); return(converter.Value); }
internal static PortableExecutableReference CreateMetadataReferenceFromHexGZipImage( string image, MetadataReferenceProperties properties = default(MetadataReferenceProperties), DocumentationProvider documentation = null, string filePath = null ) { if (image == null) { throw new ArgumentNullException(nameof(image)); } using (var compressed = new MemoryStream(SoapHexBinary.Parse(image).Value)) using (var gzipStream = new GZipStream(compressed, CompressionMode.Decompress)) using (var uncompressed = new MemoryStream()) { gzipStream.CopyTo(uncompressed); uncompressed.Position = 0; return(MetadataReference.CreateFromStream( uncompressed, properties, documentation, filePath )); } }
private FileType AnalyzeFile(string file) { // The format is stored in the first 3-4 bytes byte[] buffer = new byte[3]; string hex; using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) { fs.Read(buffer, 0, buffer.Length); SoapHexBinary shb = new SoapHexBinary(buffer); hex = shb.ToString(); } switch (hex) { case "5D0000": return(FileType.LZMA); case "474D41": return(FileType.GMAD); case "445550": return(FileType.DUPE); case "474D53": return(FileType.GMS); default: return(FileType.Uknown); } }
protected void EncodeBtn_Click(object sender, EventArgs e) { BuildNewMTI(); ISO8583FieldsUpdater Updater = new ISO8583FieldsUpdater(); foreach (ISO8583DataSet.ISO8583FieldsRow Row in Updater.m_DS.ISO8583Fields) { if (Row.IsBinary) { try { SoapHexBinary H = SoapHexBinary.Parse(Row.FieldValue); m_Msg.set_ElementValue(Row.ElementID, H.Value); } catch { ErrorText.Text = "Invalid Hex Binary Value for Element ID " + Row.ElementID.ToString(); return; } } else { m_Msg.set_ElementValue(Row.ElementID, Row.FieldValue); } } DisplayMsg(); }
public void DisplayMsg() { DisplayMTI(); ISO8583FieldsUpdater Updater = new ISO8583FieldsUpdater(); Updater.ClearAll(); foreach (object ElementID in (object[])m_Msg.ElementsIDs) { object Val = m_Msg.get_ElementValue((int)ElementID); if (Val is string) { Updater.InsertField((int)ElementID, (string)Val, false); } else { SoapHexBinary H = new SoapHexBinary((byte[])Val); Updater.InsertField((int)ElementID, H.ToString(), true); } } DataBind(); object ISOBuf = null; TValidationError Error = m_Msg.ToISO(out ISOBuf); if (Error == TValidationError.NoError) { SoapHexBinary H = new SoapHexBinary((byte[])ISOBuf); MessageHexDump.Text = H.ToString(); ISO8583XML.Text = Server.HtmlEncode(m_Msg.XML).Replace("\n", "<br/>").Replace("\t", " "); } DisplayError(Error); }
public string GetLicense(string licenseNamespace) { string code = b1DAO.ExecuteSqlForObject <string>(string.Format(this.GetSQL("GetLicenseCode.sql"), licenseNamespace)); List <String> hexFile = b1DAO.ExecuteSqlForList <String>(string.Format(this.GetSQL("GetLicense.sql"), code)); if (hexFile.Count == 0) { return(null); } try { StringBuilder sb = new StringBuilder(); foreach (var hex in hexFile) { sb.Append(hex); } SoapHexBinary shb = SoapHexBinary.Parse(sb.ToString()); byte[] buffer = Compression.Uncompress(shb.Value); return(convertoToString(buffer)); } catch (ZipException) { return(null); } }
//TODO: Performance check and improvements. private byte[] HexToByte(string hex) { if (hex.Length % 2 == 1) { Error.RecoverableError("Malformed HEX string (the one that contains the binary to scan)"); hex = hex + '0'; } //This should be faster.. SoapHexBinary shb = SoapHexBinary.Parse(hex); return(shb.Value); //If that doesn't compile/work, fall back to this: (slower) /*if (hex == null) * return null; * * * * byte[] data = new byte[hex.Length / 2]; * * for (int i = 0; i < data.Length; i++) * data[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16); * * return data;*/ }
public void ExtractInfoHash() { Bencoder bc = new Bencoder(); MnlMessage msg = new MnlMessage .Builder(ParseTest.ConvertHexStringToByteArray("64313a6164323a696432303a7200ee612a3d17f22d721a8019317eb27c7039c9393a696e666f5f6861736832303af6ef92f7cfa792c050fef70c405ded104771553d363a6e6f7365656469316565313a71393a6765745f7065657273313a74343a9b9427a4313a76343a5554ab14313a79313a7165")) .Build(); MnlMessage myMsg = new MnlMessage .Builder(ParseTest.ConvertHexStringToByteArray("64313a74323a3032313a79313a71313a71393a6765745f7065657273313a6164323a696432303a09dc0cea8478d7f285ef674c6a2f931ae3b603f4393a696e666f5f6861736832303a3f4f40163040223f3f063f3a562f603e3f543f3f6565")) .Build(); Dictionary <string, object> decoded = (Dictionary <string, object>)bc.DecodeElement(ParseTest.ConvertHexStringToByteArray("64313a6164323a696432303ab2dfb21aa9b31c00cdca99bcd9232a7facbc76e2393a696e666f5f6861736832303aa44f7b0766a4e53ebfc0cf79fa9c82778b88d94765313a71393a6765745f7065657273313a74343a67707588313a79313a7165")); Dictionary <string, object> decodedMy = (Dictionary <string, object>)bc.DecodeElement(ParseTest.ConvertHexStringToByteArray("64313a74323a3034313a79313a71313a71393a6765745f7065657273313a6164323a696432303ae36f5d8ef6928691d9696e02d025e3b8f1a08ca2393a696e666f5f6861736832303a139f69de76a07790ec3ad31cbc3bd5d9058716006565")); var infoHash = Encoding.UTF8.GetBytes((string)((Dictionary <string, object>)decoded["a"])["info_hash"]); var bytes = ParseTest.ConvertHexStringToByteArray("3F4F40163040223F3F063F3A562F603E3F543F3F"); //CollectionAssert.AreEqual(infoHash, bytes); SoapHexBinary hex = new SoapHexBinary(infoHash); Debug.WriteLine($"Info hash: {hex.ToString()} "); }
///<summary> /// /// Metodo para converter string em uma string hexadecimal /// ///</summary> public static string convertToHexa(string hexa) { byte[] toBytes = Encoding.ASCII.GetBytes(hexa); SoapHexBinary shb = new SoapHexBinary(toBytes); return(shb.ToString()); }
public static void Main(string[] args) { // Parse an XSD formatted string to create a SoapHexBinary object. string xsdHexBinary = "3f789ABC"; SoapHexBinary hexBinary = SoapHexBinary.Parse(xsdHexBinary); // Print the value of the SoapHexBinary object in XSD format. Console.WriteLine("The SoapHexBinary object in XSD format is {0}.", hexBinary.ToString()); // Print the XSD type string of this particular SoapHexBinary object. Console.WriteLine( "The XSD type of the SoapHexBinary object is {0}.", hexBinary.GetXsdType()); // Print the value of the SoapHexBinary object. Console.Write("hexBinary.Value contains:"); for (int i = 0; i < hexBinary.Value.Length; ++i) { Console.Write(" " + hexBinary.Value[i]); } Console.WriteLine(); // Print the XSD type string of the SoapHexBinary class. Console.WriteLine("The XSD type of the class SoapHexBinary is {0}.", SoapHexBinary.XsdType); }
// Pour l'utilisation de SoapHexBinary // cf. // https://stackoverflow.com/questions/311165/how-do-you-convert-a-byte-array-to-a-hexadecimal-string-and-vice-versa/2556329#2556329 static void Main(string[] args) { int keyPrefix = Array.IndexOf(args, "--key"); int contentPrefix = Array.IndexOf(args, "--content"); int signaturePrefix = Array.IndexOf(args, "--signature"); string key = args[keyPrefix + 1]; string content = args[contentPrefix + 1]; byte[] keyBytes = Encoding.UTF8.GetBytes(key); HMACSHA256 hash = new HMACSHA256(keyBytes); byte[] byteArray = Encoding.UTF8.GetBytes(content); MemoryStream stream = new MemoryStream(byteArray); byte[] signature = hash.ComputeHash(stream); SoapHexBinary shb = new SoapHexBinary(signature); string hexaRepresentation = shb.ToString(); System.Console.WriteLine(hexaRepresentation); if (signaturePrefix >= 0) { string providedSignature = args[signaturePrefix + 1]; byte[] providedSignatureBytes = SoapHexBinary.Parse(providedSignature).Value; System.Console.WriteLine(providedSignatureBytes.SequenceEqual(signature)); } return; }
public byte[] GetKeyFromAppsetting(string name) { var cfg = _config ?? GetConfig(); var values = cfg.GetValues(name); if (values == null) { throw new ApplicationException("Could not get session authentication key. The appsetting " + name + " did not exist."); } if (values.Length > 1) { throw new ApplicationException("Multiple values found for the appsetting " + name + ". Please configure only one."); } var validationKey = values[0]; string failureReason; if (!_validator.IsValidKey(validationKey, out failureReason)) { throw new ApplicationException("Invalid session authentication key in appsetting. " + failureReason); } var hexbinary = SoapHexBinary.Parse(validationKey); var key = hexbinary.Value; hexbinary.Value = new byte[0]; return(key); }
public static HashedAndSaltedPassword CryptPassword(string password, String defaultSalt = null) { var data = Encoding.UTF8.GetBytes(password); byte[] salt = null; if (defaultSalt == null) { salt = GenerateSalt(); } else { SoapHexBinary hexBinary = SoapHexBinary.Parse(defaultSalt); salt = hexBinary.Value; } var saltedpass = Combine(data, salt); HashedAndSaltedPassword hashedAndSaltedPassword = new HashedAndSaltedPassword(); using (SHA512 shaM = new SHA512Managed()) { var hash = shaM.ComputeHash(saltedpass); SoapHexBinary crypted = new SoapHexBinary(hash); SoapHexBinary salted = new SoapHexBinary(salt); hashedAndSaltedPassword.PasswordHash = crypted.ToString(); hashedAndSaltedPassword.PasswordSalt = salted.ToString(); } return(hashedAndSaltedPassword); }
public string ToHexString() { StringBuilder SBuilder = new StringBuilder(); SoapHexBinary Hex = new SoapHexBinary(ToArray()); return(Hex.ToString()); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var hex = reader.Value.ToString(); var bytes = SoapHexBinary.Parse(hex).Value; return(bytes); }
[Test] // ctor (Byte []) public void Constructor2() { byte [] bytes; SoapHexBinary shb; bytes = new byte [] { 2, 3, 5, 7, 11 }; shb = new SoapHexBinary(bytes); Assert.AreEqual("hexBinary", shb.GetXsdType(), "#A1"); Assert.AreEqual("020305070B", shb.ToString(), "#A2"); Assert.AreSame(bytes, shb.Value, "#A3"); bytes = new byte [0]; shb = new SoapHexBinary(bytes); Assert.AreEqual("hexBinary", shb.GetXsdType(), "#B1"); Assert.AreEqual("", shb.ToString(), "#B2"); Assert.AreSame(bytes, shb.Value, "#B3"); bytes = null; shb = new SoapHexBinary(bytes); Assert.AreEqual("hexBinary", shb.GetXsdType(), "#C1"); try { shb.ToString(); Assert.Fail("#C2"); } catch (NullReferenceException) { } Assert.IsNull(shb.Value, "#C3"); }
internal override void SaveAssemblyI18N(string moduleCode, string i18n, byte[] i18nAsm) { string sql; int maxtext = 256000; int insertedText = 0; string asmHex = null; b1DAO.ExecuteStatement(String.Format(this.GetSQL("DeleteModuleI18N.sql"), moduleCode)); SoapHexBinary shb = new SoapHexBinary(Compress(i18nAsm)); if (i18nAsm != null) { string insertSQL = this.GetSQL("InsertI18N.sql"); asmHex = shb.ToString(); for (int i = 0; i < asmHex.Length / maxtext; i++) { string code = b1DAO.GetNextCode("DOVER_MODULES_I18N"); sql = String.Format(insertSQL, code, code, moduleCode, asmHex.Substring(i * maxtext, maxtext), i18n); b1DAO.ExecuteStatement(sql); insertedText += maxtext; } if (insertedText < asmHex.Length) { string code = b1DAO.GetNextCode("DOVER_MODULES_I18N"); sql = String.Format(insertSQL, code, code, moduleCode, asmHex.Substring(insertedText), i18n); b1DAO.ExecuteStatement(sql); } } }
private object ParseResponseParameter(string value, string parameterTypeName) { object result = null; switch (parameterTypeName) { case "stringParameter": result = value; break; case "booleanParameter": result = bool.Parse(value); break; case "integerParameter": result = int.Parse(value); break; case "binaryParameter": result = SoapHexBinary.Parse(value).Value; break; } if (result == null) { throw new ParameterTypeNotSupportedException(parameterTypeName); } return(result); }
public static Message GetFixedData(string name = null) { return(GetSimpleMessage(name). SetContent(SoapHexBinary. Parse("000000000000007308010000016EB60A3A900002DFB72A1EBED43A0004005213001C00190B010102000300B300B4014503F0011502511E52405900074237FC180018430FB854002E55075F7300005A000006C700017C83F100004FB81007A350E55300017DDF5707A145E464000000A4014E00000000000000000100007780"). Value)); }
internal override void SaveAssembly(AssemblyInformation asm, byte[] asmBytes) { string installed = (asm.Type == AssemblyType.Core) ? "Y" : "N"; SoapHexBinary shb = new SoapHexBinary(Compression.Compress(asmBytes)); string asmHex = null; if (asmBytes != null) { asmHex = shb.ToString(); } string sql; if (String.IsNullOrEmpty(asm.Code)) { asm.Code = b1DAO.GetNextCode("DOVER_MODULES"); sql = String.Format(this.GetSQL("SaveAssembly.sql"), asm.Code, asm.Code, asm.Name, asm.Description, asm.FileName, asm.Version, asm.MD5, asm.Date.ToString("yyyyMMdd"), asmBytes.Length, asm.TypeCode, installed, asm.Namespace); } else { sql = String.Format(this.GetSQL("UpdateAssembly.sql"), asm.Version, asm.MD5, asm.Date.ToString("yyyyMMdd"), asmBytes.Length, asm.Code, asm.Description, installed); b1DAO.ExecuteStatement(String.Format(this.GetSQL("DeleteAssembly.sql"), asm.Code)); b1DAO.ExecuteStatement(String.Format(this.GetSQL("DeleteDependencies.sql"), asm.Code)); } b1DAO.ExecuteStatement(sql); // Modules binaries if (asmBytes != null) { InsertAsmBin(asm, asmHex); } }
private byte[] parse_input() { /* Identify whether the input string is * 1. Hex String - A long string with no spaces in between * 2. Offset Hex - A neatly formatted hex code with spaces after every hex code */ string input = textBox_encoded.Text.Trim(); if (input.Contains(" ")) { /* Looks like Offset hex * Offset hex string will contain the offset markers like "0000 " * They are to be removed from every line. * Use the regex pattern to remove them */ string pattern = @"\d\d\d\d\s+"; Regex regex = new Regex(pattern); input = regex.Replace(input, ""); byte[] test = input.Split().Select(s => Convert.ToByte(s, 16)).ToArray(); return(test); } else { /* No spaces. Just a long hex stream */ SoapHexBinary shb = SoapHexBinary.Parse(input); return(shb.Value); } }
private byte[] GetSessionIDAuthenticationKey() { var hexBinary = SoapHexBinary.Parse(_sessionSecurityConfig.SessionIDAuthentication.AuthenticationKey); var key = hexBinary.Value; hexBinary.Value = new byte[0]; return(key); }