locked
data type efficiency question for byte data RRS feed

  • Question

  • Not sure the best topic area, I'm using .NET and encrypting data from users via web app (as string) and was wondering if there would be any issues, etc if I saved the data in sql server as byte data, not string. I can pull and decrypt. Is is better, more efficient to store as string or byte data? The data that I'm storing might equate to a few text paragraphs.

    optimium data type for this? I've heard of using varbinary?

    Thoughts?
    Tuesday, March 16, 2010 9:13 PM

Answers

  • No, I don't see any reason to. The varbinary type is optimized for storing binary data. I really can't think of any reason how it would even make it better at all. You can work with binary data using a hex representation even when scripting data, (the hex is prefixed with 0x) but just put the data into a sql type and pass it as a parameter and it should work great.
    Louis

    Thursday, March 18, 2010 4:09 PM

All replies

  • Really depends on what format you have the data.  If it is a binary value, then varbinary is definitely best for storing binary data.   But, if you have the encrypted value as a string value, then storing it as a char() or varchar() value would be best.  Of course, if the data is of a fixed length (though it probably isn't), then don't use any of the variable types that start with var..

    What type do you use on the .NET side to hold the data?


    Louis

    Thursday, March 18, 2010 4:39 AM
  • I'm using System.Security.Cryptography.RijndaelManaged to encrypt string data to byte.
    would it be better/more efficient to convert to string for the save? i.e. using Convert.ToBase64String
    Thursday, March 18, 2010 3:19 PM
  • No, I don't see any reason to. The varbinary type is optimized for storing binary data. I really can't think of any reason how it would even make it better at all. You can work with binary data using a hex representation even when scripting data, (the hex is prefixed with 0x) but just put the data into a sql type and pass it as a parameter and it should work great.
    Louis

    Thursday, March 18, 2010 4:09 PM
  • Thanx, as a developer the DB stuff can be new (you know just enough to be dangerous).
    Thursday, March 18, 2010 7:52 PM