Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Translate string in binary value

Author  Topic 

Ciupaz
Posting Yak Master

232 Posts

Posted - 2014-01-17 : 06:10:09
Hello all,
I need to translate a normal string, for example 'MyPassword'
in its correspondent binary value, something like

0x183BDC55FE78BC519C6C5CA712DC55BDC605113B

Is it possible with T-SQL (SS 2008 R2)?

Thanks in advance.

Luis

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2014-01-17 : 07:14:43
See the CAST/CONVERT command

djj
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-01-17 : 07:23:53
quote:
Originally posted by Ciupaz

Hello all,
I need to translate a normal string, for example 'MyPassword'
in its correspondent binary value, something like

0x183BDC55FE78BC519C6C5CA712DC55BDC605113B

Is it possible with T-SQL (SS 2008 R2)?

Thanks in advance.

Luis




This does not looks like the ascii value for the string 'MyPassword'.
It looks more like a result of a HASHBYTES()

http://technet.microsoft.com/en-us/library/ms174415.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Ciupaz
Posting Yak Master

232 Posts

Posted - 2014-01-17 : 08:43:55
Thanks Khtan, so I can make it in this way:


declare @MyPassword NVARCHAR(50) = 'MyPassword'

SELECT HASHBYTES('SHA1', @MyPassword)

Luis
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-01-17 : 12:55:39
quote:
Originally posted by Ciupaz

Thanks Khtan, so I can make it in this way:


declare @MyPassword NVARCHAR(50) = 'MyPassword'

SELECT HASHBYTES('SHA1', @MyPassword)

Luis

Depends on what your goal is. You can cast/convert you can use a another function like HASHBYTES. You can also encrypt/decrypt with certificates/keys using ENCRYPTBYKEY, etc..
DECLARE @Val AS VARCHAR(50) = 'MyPassword'

SELECT
@Val,
CAST(@Val as VARBINARY(MAX)),
HASHBYTES('SHA1', @Val
Go to Top of Page
   

- Advertisement -