[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"); }
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()); }
[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 getMD5HashOfFile(string path) { try { if (string.IsNullOrEmpty(path)) throw new Exception("No args provided"); if (!File.Exists(path)) throw new Exception("File " + path + " doesn't exist."); Stream inputStream = File.OpenRead(path); HashAlgorithm algorithm = MD5.Create(); byte[] hash = algorithm.ComputeHash(inputStream); SoapHexBinary output = new SoapHexBinary(hash); return output.ToString(); } catch (Exception e) { sendError("MD5 Error --- " + e.Message.ToString()); return ""; } }
void saveOrCreateFile() { string error = ""; SoapHexBinary soap = new SoapHexBinary(encriptarint(0)); string enc = soap.ToString(); for (int i = 0; i < list.Count; i++) { string puesto = list.Item(i).Attributes.GetNamedItem("puesto").Value; XmlNodeList tmp = list.Item(i).ChildNodes; for (int j = 0; j < tmp.Count; j++) { string candidato = tmp.Item(j).Attributes.GetNamedItem("nombre").Value; string partido = tmp.Item(j).Attributes.GetNamedItem("partido").Value; string insert = "insert into candidato values(null,'" + candidato + "','" + partido + "','" + puesto + "','" + enc +"');"; if (Sqlite3.sqlite3_exec(Program.db, insert, null, null, ref error) != Sqlite3.SQLITE_OK) { MessageBox.Show(error); } } } }
private void generatePassword_DoubleClick(object sender, EventArgs e) { TextBox tb = (TextBox)sender; statusBar("Generiram ključeve",10); if (tb == tbTajni) { using (AesCryptoServiceProvider AES = new AesCryptoServiceProvider()) { AES.KeySize = 128; SoapHexBinary shb = new SoapHexBinary(AES.Key); tbTajni.Text = shb.ToString(); spremi("tajni_kljuc.txt", tbTajni.Text); } } else if (tb == tbJavni || tb==tbPrivatni) { using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048)) { tbJavni.Text = RSA.ToXmlString(false); tbPrivatni.Text = RSA.ToXmlString(true); spremi("javni_kljuc.txt", tbJavni.Text); spremi("privatni_kljuc.txt", tbPrivatni.Text); } } statusBar("Ključevi generirani i pohranjeni", 100); }
private static string urlToFile(string url) { var data = Encoding.UTF8.GetBytes(url); var hash = SHA1.Create().ComputeHash(data); var soap = new SoapHexBinary(hash); return soap.ToString(); }
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); }
///<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 int ToEpoch(this DateTime dateTime) //{ // var t = (dateTime.ToUniversalTime() - new DateTime(1970, 1, 1)); // return (int)t.TotalSeconds; //} public static string ToHex(this byte[] data) { var shb = new SoapHexBinary(data); return shb.ToString(); }
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; }
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 ()); } 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 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 ByteArrayToHexString(byte[] bytes) { var shb = new SoapHexBinary(bytes); 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 static void WriteBinaryExchange(XmlWriter writer, BinaryExchange binaryExchange, WSTrustConstantsAdapter trustConstants) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (binaryExchange == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binaryExchange"); } if (trustConstants == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("trustConstants"); } string binaryData = null; switch (binaryExchange.EncodingType.AbsoluteUri) { case WSSecurity10Constants.EncodingTypes.Base64: { binaryData = Convert.ToBase64String(binaryExchange.BinaryData); break; } case WSSecurity10Constants.EncodingTypes.HexBinary: { SoapHexBinary hexBinary = new SoapHexBinary(binaryExchange.BinaryData); binaryData = hexBinary.ToString(); break; } default: { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WSTrustSerializationException(SR.GetString( SR.ID3217, binaryExchange.EncodingType.AbsoluteUri, string.Format(CultureInfo.InvariantCulture, "({0}, {1})", WSSecurity10Constants.EncodingTypes.Base64, WSSecurity10Constants.EncodingTypes.HexBinary)))); } } writer.WriteStartElement(trustConstants.Prefix, trustConstants.Elements.BinaryExchange, trustConstants.NamespaceURI); writer.WriteAttributeString(trustConstants.Attributes.ValueType, binaryExchange.ValueType.AbsoluteUri); writer.WriteAttributeString(trustConstants.Attributes.EncodingType, binaryExchange.EncodingType.AbsoluteUri); writer.WriteString(binaryData); writer.WriteEndElement(); }
public static string ByteArrayToString(byte[] ba) { SoapHexBinary Hex = new SoapHexBinary(ba); return Hex.ToString(); }
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; } }