v5 UUID 생성. 이름과 네임 스페이스는 무엇입니까?
내가 읽은 man
페이지를하지만, 난 안 알아 보았 무슨 name
과 namespace
를위한 것입니다.
버전 3 및 버전 5 UUID의 경우 추가 명령 줄 인수 네임 스페이스 및 이름을 제공해야합니다. 네임 스페이스는 문자열 표현의 UUID이거나 내부적으로 미리 정의 된 네임 스페이스 UUID (현재 알려진 것은 "ns : DNS", "ns : URL", "ns : OID"및 "ns : X500")의 식별자입니다. 이름은 임의 길이의 문자열입니다.
네임 스페이스 :
네임 스페이스는 문자열 표현의 UUID이거나
생성 된 UUID v5와 관련하여 어딘가에 저장 (UUID v4)해야한다는 의미입니까? 두 경우 모두 자동으로 수행되지 않는 이유는 무엇입니까?
이름은 임의 길이의 문자열입니다.
name
완전히 임의의 문자열? 그렇다면 그 목적은 무엇입니까? UUID v5에서 디코딩 할 수 있습니까?
이름과 네임 스페이스를 사용하여 (아마도) 고유 한 UUID의 계층 구조를 만들 수 있습니다.
대략적으로 말하면 유형 3 또는 유형 5 UUID는 네임 스페이스 식별자를 이름과 함께 해싱하여 생성됩니다. 유형 3 UUID는 MD5를 사용하고 유형 5 UUID는 SHA1을 사용합니다. 128 비트 만 사용할 수 있고 유형을 지정하는 데 5 비트가 사용되므로 모든 해시 비트가 UUID에 포함되지 않습니다. (또한 MD5는 암호화가 손상된 것으로 간주되고 SHA1은 마지막 구간에 있으므로 "매우 안전"해야하는 데이터를 확인하는 데 사용하지 마십시오.) 즉, 계층 적 이름을 확률 적으로 고유 한 128 비트 값에 매핑하여 잠재적으로 계층 적 해시 또는 MAC처럼 작동하는 반복 가능 / 검증 가능한 "해시"함수를 생성하는 방법을 제공합니다.
(키, 값) 저장소가 있지만 하나의 네임 스페이스 만 지원한다고 가정합니다. 유형 3 또는 유형 5 UUID를 사용하여 다수의 고유 한 논리적 네임 스페이스를 생성 할 수 있습니다. 먼저 각 네임 스페이스에 대한 루트 UUID를 만듭니다. 유형 1 (호스트 + 타임 스탬프) 또는 유형 4 (무작위) UUID 일 수 있습니다. 또는 루트에 대해 하나의 임의 UUID를 만든 다음 (또는 루트로 null
UUID : 00000000-0000-0000-0000-000000000000
사용) " uuid -v5 $ROOTUUID $NAMESPACENAME
"를 사용하여 각 네임 스페이스에 대해 재현 가능한 UUID를 만들 수 있습니다 . 이제 "를 사용하여 네임 스페이스 내의 키에 대한 고유 UUID를 만들 수 있습니다.uuid -v5 $NAMESPACEUUID $KEY
". 이러한 UUID는 충돌을 피할 가능성이 높은 단일 키-값 저장소로 던져 질 수 있습니다.이 프로세스는 반복적으로 반복 될 수 있으므로 예를 들어 UUID 키와 연관된"값 "이 일종의 논리적"네임 스페이스를 나타냅니다. " "버킷, 컨테이너 또는 디렉토리와 같이 해당 UUID를 차례로 사용하여 더 많은 계층 적 UUID를 생성 할 수 있습니다.
생성 된 유형 3 또는 유형 5 UUID는 네임 스페이스 ID 및 네임 스페이스 내 이름 (키)의 (부분) 해시를 보유합니다. 메시지 MAC이 인코딩 된 메시지의 내용을 보유하는 것보다 더 이상 네임 스페이스 UUID를 보유하지 않습니다. 이름은 uuid 알고리즘의 관점에서 볼 때 "임의"(옥텟) 문자열입니다. 그러나 그 의미는 응용 프로그램에 따라 다릅니다. 논리 디렉터리 내의 파일 이름, 개체 저장소 내의 개체 ID 등이 될 수 있습니다.
이것은 적당히 많은 수의 네임 스페이스와 키에 대해 잘 작동하지만, 매우 높은 확률로 고유 한 매우 많은 수의 키를 목표로하는 경우 결국 증기가 부족합니다. 생일 문제에 대한 Wikipedia 항목 (일명 Birthday Paradox)에는 다양한 수의 키와 테이블 크기에 대해 하나 이상의 충돌 확률을 제공하는 테이블이 포함되어 있습니다. 128 비트의 경우이 방식으로 260 억 개의 키를 해싱하면 p=10^-18
(무시할 수있는) 충돌 확률이 있지만 26 조 개의 키는 p=10^-12
(1 조분의 1)에 대해 적어도 한 번의 충돌 26*10^15
확률을 증가시키고 키를 해싱 하면 하나 이상의 충돌p=10^-6
(만에 하나). UUID 유형을 인코딩하는 5 비트를 조정하면 다소 빨리 소모되므로 1 조 개의 키가 한 번의 충돌이 발생할 가능성이 약 1 조에 1 조입니다.
확률 테이블 은 http://en.wikipedia.org/wiki/Birthday_problem#Probability_table 을 참조하십시오 .
UUID 인코딩에 대한 자세한 내용 은 http://www.ietf.org/rfc/rfc4122.txt 를 참조 하십시오 .
유형 3 및 유형 5 UUID는 해시 를 UUID 에 채우는 기술입니다 .
- 유형 1 : MAC 주소, 날짜 시간을 128 비트로 채 웁니다.
- 유형 3 : MD5 해시를 128 비트로 채 웁니다.
- 유형 4 : 임의 데이터를 128 비트로 채움
- 유형 5 : SHA1 해시를 128 비트로 채 웁니다.
SHA1 해시는 160 비트 (20 바이트)를 출력합니다. 해시의 결과는 UUID로 변환됩니다. SHA1의 20 바이트에서 :
SHA1 Digest: 74738ff5 5367 e958 9aee 98fffdcd1876 94028007
UUID (v5): 74738ff5-5367-5958-9aee-98fffdcd1876
^_low nibble is set to 5 to indicate type 5
^_first two bits set to 1 and 0, respectively
( '9'의 처음 두 비트는 이미 각각 1과 0이므로 효과가 없습니다).
나는 무엇을 해시합니까?
내가 해시해야하는 것이 무엇인지 궁금 할 것입니다. 기본적으로 다음의 연결을 해시합니다.
sha1([NamespaceUUID]+[AnyString]);
이름 충돌을 방지하기 위해 소위 네임 스페이스 를 문자열 앞에 붙 입니다.
UUID RFC는 당신을 위해 네 개의 네임 스페이스를 정의합니다 사전 :
NameSpace_DNS
: {6ba7b810-9dad-11d1-80b4-00c04fd430c8}NameSpace_URL
: {6ba7b811-9dad-11d1-80b4-00c04fd430c8}NameSpace_OID
: {6ba7b812-9dad-11d1-80b4-00c04fd430c8}NameSpace_X500
: {6ba7b814-9dad-11d1-80b4-00c04fd430c8}
따라서 함께 해시 할 수 있습니다.
StackOverflowDnsUUID = sha1(Namespace_DNS + "stackoverflow.com");
StackOverflowUrlUUID = sha1(Namespace_URL + "stackoverflow.com");
그런 다음 RFC는 다음 방법을 정의합니다.
- SHA1에서 160 비트 가져 오기
- 128 비트의 UUID로 변환합니다.
The basic gist is to only take the first 128 bits, stuff a 5
in the type record, and then set the first two bits of the clock_seq_hi_and_reserved
section to 1 and 0, respectively.
More examples
Now that you have a function that generates a so-called Name , you can have the function (in pseudo-code):
UUID NameToUUID(UUID NamespaceUUID, String Name)
{
byte[] hash = sha1(NamespaceUUID.ToBytes() + Name.ToBytes());
UUID result;
Copy(hash, result, 16);
result[6] &= 0x0F;
result[6] |= 0x50;
result[8] &= 0x3F;
result[8] |= 0x80;
return result;
}
(Note that the endian-ness of your system can affect indices of the above bytes)
You can have calls:
uuid = NameToUUID(Namespace_DNS, 'www.stackoverflow.com');
uuid = NameToUUID(Namespace_DNS, 'www.google.com');
uuid = NameToUUID(Namespace_URL, 'http://www.stackoverflow.com');
uuid = NameToUUID(Namespace_URL, 'http://www.google.com/search&q=rfc+4112');
uuid = NameToUUID(Namespace_URL, 'http://stackoverflow.com/questions/5515880/test-vectors-for-uuid-version-5-converting-hash-into-guid-algorithm');
Now back to your question
For version 3 and version 5 UUIDs the additional command line arguments namespace and name have to be given. The namespace is either a UUID in string representation or an identifier for internally pre-defined namespace UUIDs (currently known are "ns:DNS", "ns:URL", "ns:OID", and "ns:X500"). The name is a string of arbitrary length.
The namespace is whatever UUID you like. It can be one of the pre-defined ones, or you can make up your own, e.g.:
UUID Namespace_RectalForeignExtractedObject = '4d79546f-6e67-7565-496e-486572417373'
The name is a string of arbitrary length.
The name is just the text you want to have appended to the namespace, then hashed, and stuffed into a UUID:
uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'screwdriver');
uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'toothbrush');
uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'broomstick');
uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'orange');
uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'axe handle');
uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'impulse body spray');
uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'iPod Touch');
Note: Any code released into public domain. No attribution required.
A name is nothing more than an identifier that is unique within some namespace. The problem is that namespaces are often quite small and the names in one often collide with names in others. For instance, my car's license plate number (name) is unique within my state DMV's namespace, but it's probably not unique in the world; other state DMVs may have used the same name in their own namespaces. Heck, someone else may have a phone number (name) that also matches because that's yet another namespace, etc.
UUIDs can be seen as inhabiting a single namespace so vast that it can provide a unique name for everything; that's what the "universal" means. But how do you map existing names in other namespaces to a UUID?
One obvious solution is to generate a UUID (V1 or V4) for every item to replace the old names in their disjoint namespaces. The downside is that they're a lot bigger, you have to communicate all the new names to everyone who has a copy of your dataset, update all your APIs, etc. Odds are you can't actually get rid of the old names entirely anyway, which means now every item has two names, so did you make things better or worse?
This is where V3/V5 come in. The UUIDs look just as random as V4 but are actually deterministic; anyone who has the right UUID for a namespace can then independently generate the same UUID for any given name within that namespace. You don't need to publish them at all nor even pre-generate them since anyone can create them on the fly as needed!
DNS names and URLs are very commonly used namespaces, so standard UUIDs were published for those; ASN.1 OIDs and X.500 names aren't as common, but standards bodies love them, so they published standard namespace UUIDs for them too.
For all other namespaces, you have to generate your own namespace UUID (V1 or V4) and communicate it to anyone who needs it. If you have several namespaces, having to publish the UUID for each one is clearly not ideal.
This is where the hierarchy comes in: you create one "base" UUID (of whatever type), and then use that as a namespace for naming your other namespaces! That way, you only have to publish the base UUID (or use an obvious one), and everyone can calculate the rest.
For instance, let's stay we wanted to create some UUIDs for StackOverflow; that has an obvious name within the DNS namespace, so the base is obvious:
uuid ns_dns = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
uuid ns_base = uuidv5(ns_dns, 'stackoverflow.com');
StackOverflow itself has separate namespaces for users, questions, answers, comments, etc., but those are fairly obvious as well:
uuid ns_user = uuidv5(ns_base, 'user');
uuid ns_question = uuidv5(ns_base, 'question');
uuid ns_answer = uuidv5(ns_base, 'answer');
uuid ns_comment = uuidv5(ns_base, 'comment');
This particular question is #10867405, so its UUID would be:
uuid here = uuidv5(ns_question, '10867405');
Notice that there's nothing random in this process, so anyone who follows the same logic will get the same answer, yet the UUID namespace is so vast that it will (effectively, given the security of a 122-bit cryptographic hash) never collide with a UUID generated from any other namespace/name pair.
참고URL : https://stackoverflow.com/questions/10867405/generating-v5-uuid-what-is-name-and-namespace
'program tip' 카테고리의 다른 글
(HTML) 클릭시 브라우저에서 열지 않고 PDF 파일 다운로드 (0) | 2020.08.26 |
---|---|
출시 후 iOS 앱에 디버거를 연결하는 방법은 무엇입니까? (0) | 2020.08.26 |
프로젝트에서 Cordova 플러그인 제거 (0) | 2020.08.26 |
테스트 실패와 관련된 전체 추적을 제공하기 위해 rspec-2를 얻는 방법은 무엇입니까? (0) | 2020.08.26 |
'nuget'은 인식되지 않지만 다른 nuget 명령은 작동합니다. (0) | 2020.08.26 |