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.

They also have to be in Hexadecimal format, so this will not work regardless.

@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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.