コード例 #1
0
        /// <summary>
        /// Computes and returns the 8-byte folded MD5 hash of the GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns>The 8-byte hash.</returns>
        /// <remarks>
        /// <para>
        /// This works by:
        /// </para>
        /// <list type="number">
        /// <item>Generating the 16-byte MD5 hash of the GUID.</item>
        /// <item>Splitting the result in half to two 8-byte arrays.</item>
        /// <item>XOR-ing the bytes of the two arrays to form a new 8-byte array.</item>
        /// <item>Retuning the result.</item>
        /// </list>
        /// </remarks>
        public static byte[] ToFoldedBytes(this Guid guid)
        {
            var md5Hash = CryptoHelper.ComputeMD5Bytes(guid.ToByteArray());
            var result  = new byte[8];  // $note(jefflill): I'm not actually splitting into two arrays.

            for (int i = 0; i < 8; i++)
            {
                result[i] = (byte)(md5Hash[i] ^ md5Hash[i + 8]);
            }

            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Computes and returns the 16-byte MD5 hash of the GUID.
 /// </summary>
 /// <param name="guid">The GUID.</param>
 /// <returns>The 16-byte hash.</returns>
 public static byte[] ToMd5Bytes(this Guid guid)
 {
     return(CryptoHelper.ComputeMD5Bytes(guid.ToByteArray()));
 }