Hi,

I encrypted two strings and returns example "euHK5s9h30Q="

then I am trying to convert the string given to GUID

 Guid tokenGuid = new Guid(encryptionString);

and i is giving me Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). error how can i resolve it please?

I'm not entirely sure what the purpose of converting to GUID is trying to achieve. A GUID is a specific format. You cannot pass arbitrary data to it and "convert" it into a GUID.

Why do you want to convert your encrypted string into a GUID?

You could for example use the String.PadLeft method to make your string 32 chars long, a format that the GUID constructor would accept.

@Ketsuekiame: Oops, forgot about hex. Athough I also don't see the need for GUID conversion, I guess it is possible to convert a charstring to a hexstring.

Something like this will work:

        string hexstring = "";
        foreach (char c in textBox1.Text)
        {
            hexstring += String.Format("{0:X}", (int)c);
        }
        hexstring = hexstring.Insert(8, "-");
        hexstring = hexstring.Insert(13, "-");
        hexstring = hexstring.Insert(18, "-");
        hexstring = hexstring.Insert(23, "-");
        Guid tokenguid = new Guid(hexstring);
        textBox3.Text = tokenguid.ToString();

Of course this means your original string must be 16 characters, as each character will be represented by 2 hex digits.

+1 for the best plausible solution, however, the OP should not be using GUID to store data.

Globally Unique IDentifier...Encryption strings can and will be the same, so using a GUID is a bad idea as it won't be unique.

This article has been dead for over six months. Start a new discussion instead.