February 16, 2011 at 4:53 am
Hi All,
how to get back the actual value from the has values generated using the Hashbytes function
Ex : for this
SELECT HashBytes('SHA1', 'SQLSERVER');
I am getting this hash value : 0x8FC8F6B21EDA2AF2FA0A6A4366ECF408B74281CD
if i pass the same hash value (0x8FC8F6B21EDA2AF2FA0A6A4366ECF408B74281CD) i want to return the "SQLSERVER"
is there any sql function or any other algorithm to perform this.
Thanks & Regards
Deepak.A
February 16, 2011 at 5:04 am
The whole point of hashing algorithms is that they are not reversable. Unless there was a specific vunerability in the hashing algorithm you could not reverse it.
I'd suggest reading up on cryptographic hashing - the point of it is not to be able to unencrypt data, but to compare two hashes to see if they are the same (e.g. to check if an entered password is correct)
February 16, 2011 at 5:04 am
Hashbytes is a one-way hash. It's not reversible and that's the whole point of a hash.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 16, 2011 at 5:16 am
hi Gail show and HowardW thanks for your reply.
I am looking something like encrypt and decrypt is there any other way in sql server we can acheive ?
Thanks and regards
Deepak.A
February 16, 2011 at 5:19 am
deepak.a (2/16/2011)
hi Gail show and HowardW thanks for your reply.I am looking something like encrypt and decrypt is there any other way in sql server we can acheive ?
Thanks and regards
Deepak.A
I really like this article from database journal; very easy to understand examples on using a certificate to encrypt and decrypt:
--http://www.databasejournal.com/features/mssql/article.php/3714031/SQL-Server-2005-Encryption-types.htm
--http://www.databasejournal.com/features/mssql/article.php/3483931/SQL-Server-2005-Security---Part-3-Encryption.htm
select EncryptedData = EncryptByPassPhrase('PEPE', '123456789' )
declare @val varbinary(max)
SET @val = 0x010000004A298120E629F7F4DC4AD09EB0E380C9E60040BDAE1DB6D8DA98C2A4D249EB71
select convert(varchar(100),DecryptByPassPhrase('PEPE',@val))
--------------------------------
if not exists(SELECT * FROM sys.certificates WHERE SUBJECT = 'Elmer Certificate')
BEGIN
CREATE CERTIFICATE ElmerEncryptionCertificate
WITH
SUBJECT = 'Elmer Certificate',
EXPIRY_DATE = '01/01/2021 '
PRINT '"Elmer Certificate" Created.'
END
ELSE
BEGIN
PRINT '"Elmer Certificate" Already Exists.'
END
DECLARE @encryptedstuff NVARCHAR(100)
SELECT @encryptedstuff = EncryptByCert(Cert_ID('ElmerEncryptionCertificate'), N'www.google.com/Search/Test')
SELECT @encryptedstuff
SELECT CAST(DecryptByCert(Cert_ID('ElmerEncryptionCertificate'), @encryptedstuff) AS NVARCHAR)
Lowell
February 16, 2011 at 6:34 am
Hi Lowell,
Iam Getting this Error
Msg 15581, Level 16, State 1, Line 3
Please create a master key in the database or open the master key in the session before performing this operation.
on execting the script
February 16, 2011 at 6:58 am
you'll really want to read the article; the master key is a prerequisite; once you have that, my snippet examples will work.
i *think* this will work no matter what?:
select EncryptedData = EncryptByPassPhrase('PEPE', '123456789' )
declare @val varbinary(max)
SET @val = 0x010000004A298120E629F7F4DC4AD09EB0E380C9E60040BDAE1DB6D8DA98C2A4D249EB71
select convert(varchar(100),DecryptByPassPhrase('PEPE',@val))
Lowell
February 16, 2011 at 7:08 am
Please, please do some reading before you start playing with encryption. If you don't know how or why a script works, you shouldn't just be running it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 16, 2011 at 7:26 am
Look up and play with EncryptByPassPhrase first. Once you have that going, look into EncryptByKey. EncryptByPassPhrase doesn't have all the setup requirements that encryption by symmetric key has. And listen to Gail - don't run random scripts if you don't know what they do.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply