May 31, 2009 at 7:06 am
Hi all
I have a simple qusetion ,can I encrypt and decrypt char column ?
Thanks in advance
May 31, 2009 at 7:44 am
Yes u can encrypt/decrypt character column. But how are you planning to do that?
May 31, 2009 at 2:04 pm
I using Symmetric Key Encryption Option as following
1.Create DMK
2.Create Certificate
3.Create Symmetric Key
And then use simple update Syntax as following
OPEN SYMMETRIC KEY TestTableKey DECRYPTION
BY CERTIFICATE EncryptTestCert
UPDATE TestTable
SET Mycolumn = ENCRYPTBYKEY(KEY_GUID('TestTableKey'),Mycolumn)
GO
And Decrypt by following script
OPEN SYMMETRIC KEY TestTableKey DECRYPTION
BY CERTIFICATE EncryptTestCert
SELECT DECRYPTBYKEY(EncryptSecondCol) AS DecryptSecondCol
FROM TestTable
GO
First problem, Decryption by using above syntax get NULL value!!!!!
Second problem, encryption not display as normal format when column is VARBINARY
Just a clarify my column data type is Char(19)
Thanks in advance
May 31, 2009 at 8:33 pm
you'll need to change your encrypted column to a varbinary. I believe the rule is if you are doing a 19 char field, the size for the varbinary is twice the size, so it must be a varbinary(38)( or larger)
the function ENCRYPTBYKEY returns a varbinary with a maximum size of 8,000 bytes.
you are getting weird data and truncation when you decrypt the field; i'd guess NULL is the default value when you the value in the char(19) field does not translate correctly; also not ethe decrypt function expected varbinary input, but implicit conversion from text to varbinary must not raise an error.
http://msdn.microsoft.com/en-us/library/ms174361.aspx
Return Types
varbinary with a maximum size of 8,000 bytes.
Lowell
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply