0

I'm looking for way of encrypting/decrypting a specific value but with different output every time.

I have a list of users and each has an UserId which is a Guid.

User1: 00838CED-6926-4632-830F-B8F509BEC0F5

User2: 7DEAAC47-FE88-4943-BFDE-AAC986F65A23

User3: ECBB005F-1E6B-441A-8538-944383D6C0AE
.........
UserN: 479A344E-364D-4DA7-A3F8-99D94301815F

Then I want to be able to encrypt these guids in such a way that each time I get a different output. And when I decrypt it it will get me that UserId which is the guid.

Any ideas?

4
  • 1
    Add a random string to the end of the GUID each time you encrypt, and strip it off and discard it when you decrypt. Commented Aug 18, 2014 at 12:14
  • @RichieHindle: can you describe what you mean? Commented Aug 18, 2014 at 12:15
  • 1
    I've expanded my comment into an answer. Commented Aug 18, 2014 at 12:18
  • FYI, this is called salting. Do a search for "salting passwords" :) Commented Aug 18, 2014 at 12:22

2 Answers 2

1

Add a random string to the end of the GUID each time you encrypt, and strip it off and discard it when you decrypt.

To encrypt:

# Add a random string to the end of the GUID before encrypting
encrypted = encrypt(guid + ":" + a_random_string)

To decrypt:

# Strip off and discard the random string after decrypting.
guid = decrypt(encrypted).split(':')[0]
Sign up to request clarification or add additional context in comments.

Comments

0

For that you can create a custom class.Go like this in that class

1.Add an unique string like datetime to the userid at the end
2.encrypt the value
3.Store it in dictionary with key as string and encrypted userid as value
4.Reverse the process on decryption.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.