UUID 版本 5(将哈希转换为 guid)生成算法的测试向量? [英] Test vectors for UUID version 5 (converting hash into guid) generation algorithm?

查看:28
本文介绍了UUID 版本 5(将哈希转换为 guid)生成算法的测试向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试寻找一些测试向量来检查我对 UUID 版本 5 的 RFC 4122.

i'm trying to find some test vectors to check my implementation of RFC 4122 of UUID version 5.

4.3 创建基于名称的 UUID 的算法

UUID 的第 3 版用于将 MD5 哈希值放入 GUID.

Version 3 of a UUID is for putting an MD5 hash into a GUID.

UUID 的第 5 版用于将 SHA1 哈希值放入 GUID.

Version 5 of a UUID is for putting an SHA1 hash into a GUID.

RFC 在 C 中有示例实现:

The RFC has sample implementation in C:

void uuid_create_sha1_from_name(
   uuid_t *uuid,         /* resulting UUID */
   uuid_t nsid,          /* UUID of the namespace */
   void *name,           /* the name from which to generate a UUID */
   int namelen           /* the length of the name */
);

我已经用我正在使用的语言编写了自己的实现.考虑到字节序与网络顺序引起的大量麻烦,我确定我的实现是错误的.

i've written my own implementation in the language that i'm using. Considering the amount of headaches caused by endian vs network order, i am sure my implementation is wrong.

我想要一些示例数据,例如:

i'd like some sample data, e.g.:

uuid = NameToGUID(
      {6ba7b811-9dad-11d1-80b4-00c04fd430c8}, //Namespace_URL
      "https://stackoverflow.com/questions/5515880"); //a url
CheckEquals(
      {8ABAD867-F515-3CF6-BB62-5F0C88B3BB11}, //expected uuid
      uuid);

另见

  • 如何创建确定性指南
  • 推荐答案

    UUID 的德语维基百科条目www.example.org 提供了一个示例:

    The german Wikipedia entry for UUIDs got an example for www.example.org:

    6ba7b810-9dad-11d1-80b4-00c04fd430c8 // namespace UUID
    www.example.org                      // url
    74738ff5-5367-5958-9aee-98fffdcd1876 // expected UUID
    

    除此之外,Java 提供了一个 UUID 类 可以用来生成测试数据.(这似乎只能生成版本 1、2、3 和 4 UUID.)

    Apart from that, Java offers a UUID class you could use to generate test data. ( This only seems to be able to generate version 1,2,3 and 4 UUIDs.)

    您链接的问题中有一个答案,其中提到了一些可以生成版本 3/5 UUID 的库:

    There's an answer in the question you linked that mentions some libraries that can generate version 3/5 UUIDs:

    似乎有几个库出来了用于生成版本 3/5UUID,包括 python uuid模块,boost.uuid (C++) 和 OSSPUUID.(我没有寻找任何 .net个)

    There seem to be a few libraries out there for generating version 3/5 UUIDs, including the python uuid module, boost.uuid (C++) and OSSP UUID. (I haven't looked for any .net ones)

    <小时>

    OP 编辑​​

    DE wikipedia 上的例子有一个小错误:

    The example on the DE wikipedia has a slight mistake:

    • 它声称使用了 DNS 名称 www.example.org
    • 给定的 ASCII 字节序列用于 www.example.com
    • 但 SHA1 哈希使用的是 www.example.org.

    我会编辑页面以更改从
    的字节序列0x63 0x6f 0x6d "com"

    0x6f 0x72 0x67 "组织"

    i would edit the page to change the byte sequence from
    0x63 0x6f 0x6d "com"
    to
    0x6f 0x72 0x67 "org"

    但我不会说德语,不想创建帐户,而且我太懒了

    but i don't speak german, don't want to create an account, and am just all around too lazy

    这个例子归结为

    Namespace_DNS: {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
    Name:          "www.example.org"
    

    连接字节序列:

    Bytes:         6b a7 b8 10 9d ad 11 d1 80 b4 00 c0 4f d4 30 c8   {6ba7b810-9dad-11d1-80b4-00c04fd430c8}
                   77 77 77 2e 65 78 61 6d 70 6c 65 2e 6f 72 67      "www.example.org"
    

    使用 SHA1 对字节序列进行哈希处理,并将其中大部分直接复制到 UUID 中:

    Hash the byte sequence with SHA1, and copy most of it directly into a UUID:

    SHA1 Digest:   74738ff5 5367 e958 9aee98fffdcd187694028007
    UUID (v5):     74738ff5-5367-5958-9aee-98fffdcd1876
                                 ^    ^
    

    并注意将半字节之一转换为 5(表示版本 5).
    并将另一个字节的前 2 位设置为二进制 10xxxxxx.

    And take note of the conversion of one of the nibbles to 5 (to signify version 5).
    And the top 2 bits of another byte are set to binary 10xxxxxx.

    这篇关于UUID 版本 5(将哈希转换为 guid)生成算法的测试向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆