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); } } }
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 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; }
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); }
// 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 override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var bytes = (byte[])value; var hex = new SoapHexBinary(bytes); writer.WriteValue(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()); }
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); } }
public string ToHexString() { StringBuilder SBuilder = new StringBuilder(); SoapHexBinary Hex = new SoapHexBinary(ToArray()); return(Hex.ToString()); }
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 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()} "); }
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); }
/// <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()); }
[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"); }
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); } }
public static string GetHexStringFromBytes(byte[] val) { if (val == null) { return(null); } SoapHexBinary shb = new SoapHexBinary(val); return(shb.ToString()); }
private void spremiTajniKljuc_Click(object sender, EventArgs e) { using (AesCryptoServiceProvider AES = new AesCryptoServiceProvider()) { AES.KeySize = 128; SoapHexBinary shb = new SoapHexBinary(AES.Key); tekstZaAesKljuc.Text = shb.ToString(); File.WriteAllText("tajni_kljuc.txt", tekstZaAesKljuc.Text); } }
static void Main(string[] args) { X509Certificate2 cert = new X509Certificate2(args[0]); SHA256 sha = new SHA256CryptoServiceProvider(); byte[] result = sha.ComputeHash(cert.GetPublicKey()); SoapHexBinary shb = new SoapHexBinary(result); Console.WriteLine(shb.ToString()); }
static void Ctor1() { //<snippet21> // Create a SoapHexBinary object. SoapHexBinary hexBinary = new SoapHexBinary(); hexBinary.Value = new byte[] { 2, 3, 5, 7, 11 }; Console.WriteLine("The SoapHexBinary object is {0}.", hexBinary.ToString()); //</snippet21> }
static void Ctor2() { //<snippet22> // Create a SoapHexBinary object. byte[] bytes = new byte[] { 2, 3, 5, 7, 11 }; SoapHexBinary hexBinary = new SoapHexBinary(bytes); Console.WriteLine("The SoapHexBinary object is {0}.", hexBinary.ToString()); //</snippet22> }
[Test] // ctor () public void Constructor1() { SoapHexBinary shb = new SoapHexBinary(); Assert.AreEqual("hexBinary", shb.GetXsdType(), "#1"); try { shb.ToString(); Assert.Fail("#2"); } catch (NullReferenceException) { } Assert.IsNull(shb.Value, "#3"); }
public static string ArchetypeDigest(ARCHETYPE archetype) { var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = true, Indent = false }; //#if DEBUG // using (var writer = XmlWriter.Create(@".\CanonicalArchetype2.xml", new XmlWriterSettings { Indent = true })) // AmSerializer.Serialize(writer, archetype); //#endif byte[] data; using (MemoryStream stream = AmSerializer.Serialize(settings, archetype)) { #if XMLParser AmSerializer.ValidateArchetype(stream); #endif data = stream.ToArray(); } // Remove UTF-8 BOM int offset = 0; if (data.Length < 1) { throw new ApplicationException("Canonical archetype model must have length greater than 0"); } if (data[0] == 239) // UTF-8 BOM: EF BB BF (239 187 191) { offset = 3; if (data.Length <= offset) { throw new ApplicationException("Canonical archetype model must have length greater than the BOM offset"); } } if (data[offset] != 60) // XML root element (<) { throw new ApplicationException("Unexpected start character of canonical archetype model"); } MD5 md5 = new MD5CryptoServiceProvider(); SoapHexBinary hexEncoder = new SoapHexBinary(md5.ComputeHash(data, offset, data.Length - offset)); return(hexEncoder.ToString()); }
public static string RSAEncrypt(string data, string key) { try { RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(key); byte[] plainbytes = Encoding.Unicode.GetBytes(data); byte[] cipherbytes; cipherbytes = rsa.Encrypt(plainbytes, true); SoapHexBinary so = new SoapHexBinary(cipherbytes); return(so.ToString()); } catch { return(null); } }
private static void reportHandler(Report report, object parameter) { Console.WriteLine("Received report:\n----------------"); Console.WriteLine(" for RCB: " + report.GetRcbReference()); if (report.HasTimestamp()) { Console.WriteLine(" timestamp: " + MmsValue.MsTimeToDateTimeOffset(report.GetTimestamp()).ToString()); } MmsValue values = report.GetDataSetValues(); byte[] entryId = report.GetEntryId(); if (entryId != null) { SoapHexBinary shb = new SoapHexBinary(entryId); Console.WriteLine(" entryID: " + shb.ToString()); } if (report.HasDataSetName()) { Console.WriteLine(" report data set: " + report.GetDataSetName()); } Console.WriteLine(" report dataset contains " + values.Size() + " elements"); for (int i = 0; i < values.Size(); i++) { if (report.GetReasonForInclusion(i) != ReasonForInclusion.REASON_NOT_INCLUDED) { Console.WriteLine(" element " + i + " included for reason " + report.GetReasonForInclusion(i).ToString() + " " + values.GetElement(i)); } if (report.HasDataReference()) { Console.WriteLine(" data-ref: " + report.GetDataReference(i)); } } ReportControlBlock rcb = (ReportControlBlock)parameter; Console.WriteLine(" For RCB: " + rcb.GetObjectReference() + " Buffered: " + rcb.IsBuffered() + " data-set: " + rcb.GetDataSetReference()); }
public static byte[] CreateMessageWithPrependedSignatureAndPublicKey( CngKey snKey, ref StringBuilder pubKeyHashString) { byte[] signedMessage = null; // // Get the public key // byte[] snKeyPublic = snKey.Export(CngKeyBlobFormat.GenericPublicBlob); // // Hash the public key // SHA1 sha = new SHA1CryptoServiceProvider(); byte[] snKeyHash = sha.ComputeHash(snKeyPublic); // // Sign the hash // SafeNCryptKeyHandle keyHandle = snKey.Handle; byte[] sig = NCryptNative.SignHashPkcs1(keyHandle, snKeyHash, "SHA1"); // // Compose the message // signedMessage = new byte[snKeyPublic.Length + sig.Length]; sig.CopyTo(signedMessage, 0); snKeyPublic.CopyTo(signedMessage, sig.Length); // // Encode the public key hash to string // SoapHexBinary shb = new SoapHexBinary(snKeyHash); pubKeyHashString = new StringBuilder(shb.ToString()); return(signedMessage); }
private void SetDataView(TextBox textBox, byte[] data, kViewType viewType) { switch (viewType) { case kViewType.eHexadecimal: SoapHexBinary text = new SoapHexBinary(data); textBox.Text = text.ToString(); break; case kViewType.eString: textBox.Text = System.Text.Encoding.ASCII.GetString(data); break; default: //TODO break; } }
/// <summary> /// Load the <see cref="X509Certificate2" /> /// from the given <paramref name="element" /> /// </summary> /// <param name="element"></param> public override void LoadXml(XmlElement element) { var ns = new XmlNamespaceManager(new NameTable()); ns.AddNamespace("wsse", Constants.Namespaces.WssSecuritySecExt); var xmlKeyIdentifier = element.SelectSingleNode("//wsse:SecurityTokenReference/wsse:KeyIdentifier", ns) as XmlElement; if (xmlKeyIdentifier == null) { throw new XmlException( "No <wsse:KeyIdentifier/> element found in <wsse:SecurityTokenReference/> element"); } byte[] base64Bytes = Convert.FromBase64String(xmlKeyIdentifier.InnerText); var soapHexBinary = new SoapHexBinary(base64Bytes); _certificateSubjectKeyIdentifier = soapHexBinary.ToString(); }
private string GetHexStringFromBytes(byte[] bytArInput) { string strOutput = string.Empty; if (bytArInput.Length > 0) { SoapHexBinary hexBinary = null; try { hexBinary = new SoapHexBinary(bytArInput); } catch (Exception ex) { MessageBox.Show(ex.Message); } strOutput = hexBinary.ToString(); } return(strOutput); }
public XElement ToXElement(string propertyName) { if (this.Kind == 0) { this.Kind = (int)Utils.GetValueKind(this.Value); } XElement xelement = new XElement("Value", new object[] { new XAttribute("Name", propertyName), new XAttribute("Kind", this.Kind.ToString()) }); if (this.Kind == 7) { string[] array = (from o in (object[])this.Value select o.ToString()).ToArray <string>(); foreach (string value in array) { XElement content = new XElement("String") { Value = value }; xelement.Add(content); } } else if (this.Kind == 3) { SoapHexBinary soapHexBinary = new SoapHexBinary((byte[])this.Value); xelement.Value = soapHexBinary.ToString(); } else { xelement.Value = this.Value.ToString(); } return(xelement); }
public static string GetBytesToString(byte[] value) { SoapHexBinary shb = new SoapHexBinary(value); return(shb.ToString()); }