I know that you can convert binary data to nvarchar and save in the nvarchar column, and then return it back to binary when it is extracted. Will this work correctly all the time to provide you with raw binary data? Or can something be mixed up in translation?
I ask because we have an nvarchar column that stores passwords in plain text. I would like this to change to save PW in ciphertext. If I use the EncryptByPassPhrase function, it returns varbinary . I am wondering if I can just convert the output from EncryptByPassPhrase to nvarchar and save the "Password" in the same column. This would be easier than creating a new varbinary column to save the encrypted PW.
Therefore, I suggest converting current passwords as follows:
UPDATE Users SET Password = CONVERT(nvarchar(200), EncryptByPassPhrase('whatever', Password))
Then I would decrypt and extract the PW as:
SELECT CONVERT(nvarchar(200), DecryptByPassPhrase('whatever', Password)) AS PW FROM Users
Will this work correctly?
Thanks in advance!
source share