DECRYPTBYPASSPHRASE is not working after creating them with EncryptByPassPhrase

℡╲_俬逩灬. 提交于 2021-01-27 13:32:47

问题


I have a table:

CREATE TABLE TempHashedValues(
HashedValues varbinary(200)
)

Now, I am inserting encrypted values to it using, so that could be used later:

Insert into TempHashedValues values ( EncryptByPassPhrase('key', 'SecretEncoded' ))

Now when I am trying to decrypt them using same key:

Select TOP 1 DECRYPTBYPASSPHRASE('key',HashedValues) from  TempHashedValues

I am just getting the binary value back , not the value I encrypted !!

What am I missing?


回答1:


As stated here http://sqlity.net/en/2530/decryptbypassphrase/ ENCRYPTBYPASSPHRASE returns the encrypted value as a VARBINARY(8000) data type. That data type, other than for example SQL_VARIANT does not carry any information about the originating data type. Therefore, the DECRYPTBYPASSPHRASE also returns a VARBINARY(8000) value. You have to cast it :

Select TOP 1 (CAST(DECRYPTBYPASSPHRASE('key',HashedValues) AS VARCHAR(8000))) from  TempHashedValues


来源:https://stackoverflow.com/questions/43314752/decryptbypassphrase-is-not-working-after-creating-them-with-encryptbypassphrase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!