I want to convert a string (like "abcd123456" ) into a guid and from that guid I want to extract the string from that guid is there any process to do that? (will be more helpful if the example is in python or c#)
-
1Can you tell us the equivalent GUID of abcd123456 – Vivek Nuna Jun 16 '20 at 11:37
-
Do you want to create a guid from "abcd123456", and then turn the guid back into "abcd123456"? – JonasH Jun 16 '20 at 11:41
2 Answers
Guid is typically 32 character hexa decimal value. You can one way hash your string to create a Guid (like the following example. But that will loose it's meaning, i.e it is not reversible.
I think you probably in need of simple symmetric encryption method. i.e use one key to encrypt and decrypt your data. Please have a look at the following C# examples
https://learn.microsoft.com/en-us/dotnet/standard/security/encrypting-data
https://www.c-sharpcorner.com/article/encryption-and-decryption-using-a-symmetric-key-in-c-sharp/

- 621
- 5
- 15
A GUID is 128 bits. You want to be able to reverse the GUID back to the originating string, so you need to use a 128 bit block cipher. That means AES.
Take your initial string. Add cryptographic padding as needed to make it up to a 128 bits (16 bytes) and encrypt with your chosen key. Use PKCS#7 padding unless you have reason not to.
To retrieve your initial string, decrypt with the same key and remove the padding if present.
You will not be able to do this with strings longer than 16 bytes because the encrypted string will not fit into a single GUID. You would need multiple GUIDs for that.

- 15,344
- 1
- 24
- 38