Translate

Sonntag, 25. Oktober 2015

C# SHA256 hashing

using System;
using System.Security.Cryptography;
using System.Text;
 public class Hash
    {
    public static string getHashSha256(string text)
    {
        byte[] bytes = Encoding.UTF8.GetBytes(text);
        SHA256Managed hashstring = new SHA256Managed();
        byte[] hash = hashstring.ComputeHash(bytes);
        string hashString = string.Empty;
        foreach (byte x in hash)
        {
            hashString += String.Format("{0:x2}", x);
        }
        return hashString;
    }
}
 
2.
 
public static String sha256_hash(String value) {
  StringBuilder Sb = new StringBuilder();

  using (SHA256 hash = SHA256Managed.Create()) {
    Encoding enc = Encoding.UTF8;
    Byte[] result = hash.ComputeHash(enc.GetBytes(value));

    foreach (Byte b in result)
      Sb.Append(b.ToString("x2"));
  }

  return Sb.ToString();
} 

URANG-Unique Random Number Generator

URANG-Unique Random Number Generator
A programm to generate unique numbers with a specified length.
Ein Programm, um eindeutige Seriennummern zu generieren.
Readme
Plattform: Windows mit .Net 4.5.1

XML-Standardheader

<?xml version="1.0" encoding="UTF-8" ?>
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Chars>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_#$?=</Chars>
    <Density>0.55</Density>
</Config>

XMLParsing mit C#

private Config InitConfiguration(string filename)
        {
            try
            {
                XDocument xDocument = XDocument.Load(filename);
                return CreateObjectsFromString<Config>(xDocument);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return null;
            }
        }

        private T CreateObjectsFromString <T> (XDocument xDocument)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
            return (T)xmlSerializer.Deserialize(new StringReader(xDocument.ToString()));
        }

Benutzen: 
Config config = InitConfiguration(AppDomain.CurrentDomain.BaseDirectory + "Config.xml");

Die Klasse Config:

public class Config
    {
        private string chars;
        public string Chars
        {
            get
            {
                return chars;
            }
            set
            {
                chars = value;
            }
        }

        private double density;
        public double Density
        {
            get
            {
                return density;
            }
            set
            {
                density = value;
            }
        }
    }

Use a BackgroundWorker in C#

Synology Server (Synology DiskStation DS216se)