Quantcast
Channel: SQL Server Security forum
Viewing all articles
Browse latest Browse all 3042

encryptbykey(key_guid('key_DataShare'), 'MyData' ) gives different value each time? how this column can be used in Calculated column?

$
0
0

Hi All,

Why encryptbykey(key_guid('key_DataShare'),'MyData' ) gives different value on each run?

Is this expected behavior?

Is there any way can get same value on each run..?

How can one useencrypted column inHASHBYTES calculated column and this calculated column is used to merge the data from Staging to Destination?

I have a calculated Column on a table and using (HASHBYTES('SHA1', ( ISNULL(CONVERT([VARCHAR](MAX), 'MyData'), ' ')))) ENCRYPT_Column1

But When I try this (HASHBYTES('SHA1', ( ISNULL(CONVERT([VARCHAR](MAX), encryptbykey(key_guid('key_DataShare'), 'MyData' )), ' ')))) ENCRYPT_Column2 on Staging table and based on columns ENCRYPT_Column1 and ENCRYPT_Column2 try to merge the data to destination table, erach time it is inserting new record as on each run (HASHBYTES('SHA1', ( ISNULL(CONVERT([VARCHAR](MAX), 'MyData'), ' ')))) is giving different value. 

Code:

CREATEMASTERKEY ENCRYPTION BYPASSWORD = 'My p@55w0Rd'; GO CREATE CERTIFICATE [cert_keyProtection] WITH SUBJECT = 'Key Protection'; GO CREATE SYMMETRIC KEY [key_DataShare] WITH KEY_SOURCE = 'My key generation bits. This is a shared secret!', ALGORITHM = AES_256, IDENTITY_VALUE = 'Key Identity generation bits. Also a shared secret' ENCRYPTIONBY CERTIFICATE [cert_keyProtection]; GO

OPEN SYMMETRIC KEY [key_DataShare] DECRYPTION BY CERTIFICATE cert_keyProtection; GOSELECT encryptbykey(key_guid('key_DataShare'),'MyData' ) GO

https://benjii.me/2010/05/how-to-use-sql-server-encryption-with-symmetric-keys/


Thanks Shiven:) If Answer is Helpful, Please Vote





Viewing all articles
Browse latest Browse all 3042

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>