Click here to Skip to main content
12,997,531 members (58,800 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 27 Jul 2006

GUID Generator based on SHA1

, 27 Jul 2006
Rate this:
Please Sign up or sign in to vote.
GUID Generator based on SHA1
Sample Image - screen.gif


The GUID generator GuidGen.exe provided by VC can only generate random GUID. This tool can generate GUID base on a string such as class name. This means one class name maps to one GUID.


RFC 4122 described the algorithm for creating a Name-Based UUID.

The requirements for these types of UUIDs are as follows:

  • The UUIDs generated at different times from the same name in the same namespace MUST be equal.
  • The UUIDs generated from two different names in the same namespace should be different (with very high probability).
  • The UUIDs generated from the same name in two different namespaces should be different with (very high probability).
  • If two UUIDs that were generated from names are equal, then they were generated from the same name in the same namespace (with very high probability).

The algorithm for generating a UUID from a name and a namespace are as follows:

  • Allocate a UUID to use as a "name space ID" for all UUIDs generated from names in that namespace; see Appendix C for some pre-defined values.
  • Choose either MD5 [4] or SHA-1 [8] as the hash algorithm; If backward compatibility is not an issue, SHA-1 is preferred.

Using the Code

I used the sample implementation code from the RFC 4122 document and I fixed the code to let it use openssl implementation of SHA1.

#include <openssl/crypto.h>
#include <openssl/md5.h>
#include <openssl/sha.h>

It uses SHA1 to generate UUID:

uuid_create_sha1_from_name(&id, NameSpace_DNS, ss, length);

You can change it to use MD5 easily:

uuid_create_md5_from_name(&id, NameSpace_DNS, ss, length);

To build the source code, you need to download openssl from, and build it as its guide.

Or you can just use the demo tool, it requires .NET Framework runtime.


  • 27th July, 2006: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

ZhengPing Wang
Software Developer (Senior)
China China
Programmer live in china.
Interesting with knowledge management.

My home page:

You may also be interested in...

Comments and Discussions

Generalmd5.h Pin
dt29291-Oct-10 4:07
memberdt29291-Oct-10 4:07 
GeneralVisual C++ 2008 compiling failed Pin
hackxer9-Oct-09 2:47
memberhackxer9-Oct-09 2:47 
GeneralLicense requirements Pin
Gajendra Sharma23-Jul-09 23:41
memberGajendra Sharma23-Jul-09 23:41 
GeneralRe: License requirements Pin
ZhengPing Wang31-Jul-09 3:23
memberZhengPing Wang31-Jul-09 3:23 
QuestionEthernet or token-ring hardware address? Pin
Perry Zhu31-Jul-06 16:09
memberPerry Zhu31-Jul-06 16:09 
AnswerRe: Ethernet or token-ring hardware address? Pin
ZhengPing Wang31-Jul-06 16:39
memberZhengPing Wang31-Jul-06 16:39 
GeneralRe: Ethernet or token-ring hardware address? Pin
Perry Zhu31-Jul-06 21:17
memberPerry Zhu31-Jul-06 21:17 
GeneralRe: Ethernet or token-ring hardware address? Pin
ZhengPing Wang31-Jul-06 22:55
memberZhengPing Wang31-Jul-06 22:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 28 Jul 2006
Article Copyright 2006 by ZhengPing Wang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid