ApexLumia.Utils.sha256ify C# (CSharp) Метод

sha256ify() публичный статический Метод

Hash a string using SHA256
public static sha256ify ( string thing ) : string
thing string The string to hash.
Результат string
        public static string sha256ify(string thing)
        {
            byte[] thebytesofthing = UTF8Encoding.UTF8.GetBytes(thing);
            HashAlgorithm algorithm = new SHA256Managed();
            byte[] sha256ifiedbytes = algorithm.ComputeHash(thebytesofthing);

            string hex = "";
            foreach (byte x in sha256ifiedbytes) { hex += String.Format("{0:x2}", x); }

            return hex;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Upload a new telemetry_doc to Habitat.
        /// </summary>
        /// <param name="fullsentence">The full, UKHAS style sentence ($$BLA,,,,,*CHECKSUM)</param>
        public void uploadTelemetry(string fullsentence)
        {
            // This should really really really take into account the fact that
            // if it already exists, we just want to add our receiver details.

            // BUT, I can't be bothered since we're always going to be the first
            // ones to upload it since it won't have been transmitted yet

            // PLUS, if we're not the first person, then we don't really care
            // about ensuring the system knows we 'received' it too.

            string type         = "payload_telemetry";
            string _raw         = Utils.base64ify(fullsentence + "\n");
            string id           = Utils.sha256ify(_raw);
            string timecreated  = Utils.rfc3339();
            string timeuploaded = Utils.rfc3339();

            var telemetry_doc = new Dictionary <string, object>()
            {
                { "type", type },
                { "data",
                  new Dictionary <string, object>()
                  {
                      { "_raw", _raw }
                  } },
                { "receivers",
                  new Dictionary <string, object>()
                  {
                      { _callsign,
                        new Dictionary <string, object>()
                        {
                            { "time_created", timecreated },
                            { "time_uploaded", timeuploaded }
                        } }
                  } }
            };

            string json = JsonConvert.SerializeObject(telemetry_doc);

            couch.uploadDocument(json, id);
        }