Thursday, February 02, 2006

Varchar To Varbinary And Vice Versa

I have received an email from someone in Taiwan who looked at the contact me blog entry and wanted to know how I ‘encrypted’ my email address like that. Well there really is not much to it, you just convert the email string to varbinary. Then you convert it back to varchar to get the string back
For example if my email address is abc@qwerty.NotCom then you would do
SELECT CONVERT(VARBINARY(17),'abc@qwerty.NotCom')

This would return 0x616263407177657274792E4E6F74436F6D

Then you do
SELECT CONVERT(VARCHAR(17),0x616263407177657274792E4E6F74436F6D)
to see the string again
Of course you will have to increase the size of the varchar and the varbinary field if it exceeds 17 bytes

No comments: