Question

I am introducing Symmetric Key encription on some dynamically generated Sql Server 2012 tables.

I expect to store:

  1. varchar(X)
  2. integers
  3. date time
  4. boolean

I create the key using

CREATE SYMMETRIC KEY MyKey
    WITH ALGORITHM = AES_256
    ENCRYPTION BY CERTIFICATE MyCertificate
GO

I insert data using i.e.

insert into SecureTable(value) values (EncryptByKey(@ui, CONVERT(varbinary(max), 12345)))

The result is something like:

0x0022377E67EFF34DAAAD0F812153593D01000000C867C6F2085D3850BF1F50275945CFEA90297C51D537E8C443B5F34050B325E0

How can I effectively size the target columns? Using Always VARBINARY(MAX) doesn't feel right!

I'm looking for something like:

  • int => varbinary(32)
  • varchar(x) => varbinary(Y)
  • boolean => varbinary(10)
  • DataTime => ...
Was it helpful?

Solution

As suggested by @Joe Enos I tryed to encrypt several data types. This is the empiric result:

  • integer: takes 52 bytes
  • varchar(X): takes X+45 to X+65 bytes
  • float: 68 bytes
  • decimal(30,12): 68 bytes
  • datetime: 68 bytes
  • bit: 52 bytes
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top