Re: TripleDES output size



It depends on how you are converting your string data to binary (what
encoding) and how you are converting your binary cipher data back to a
string.

If you are using UTF-8 for converting string to binary (generally a good
idea), then the downside there is that the binary data can be variable
length, depending on the characters in the string. If you use Unicode
encoding, then you should always get two bytes per character.

Then, you can figure out how many bytes of cipher data you'll get by
rounding up to the block size.

If you convert from your binary data to string with Base64 (which is
probably the best way to go, as it is smaller than hex string and won't
result in lossy conversion), then the base64 string will be 4/3 the size of
the binary data.

Make sense?

Are you just trying to decide how big to make your columns in SQL given
input strings of a certain length?

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Arturo Buonanni" <leave_this_out_deer.chief.this.also@xxxxxxxxx> wrote in
message news:3ivki25mnjtgc3vkhigjl8icetgcd2krtu@xxxxxxxxxx
On 5 Oct 2006 23:28:53 -0700, "Valery Pryamikov" <valery@xxxxxxxxx>
wrote:

Thanks for your reply but it doesn't help me.

I mean. Let's say I've a 5 chars string I want to encrypt.
Encrypting it using .NET framewirk TripleDESCryptoServiceProvider
gives me a string of 24 chars lenght.
Now how can I calculate the length of the crypted string based on the
size of the plain one?

Thanks.

HI,
3DES has 8 bytes (64 bits) block size.
if you use it with default CBC mode of encryption, the last block is
always padded to make it a full block. In case if plain text size is
exact multiple of 8 bytes, then the whole block of padding is added.

-Valery.
http://www.harper.no/valery

Arturo Buonanni wrote:
Hello to all,

I'm new to cryptography and I've to implement encryption of data into
a database.
I'm using .NET framework TripleDESCryptoServiceProvider to crypt and
decrypt strings.
Anyway I can not find any reference on how to calculate the length of
the encrypted string based on the length of the plain string.
As I've to store the encrypted data into table fields, I've to be sure
it fits into the field size.

Does anybody knows how to do this?

Thanks.
(I'm posting this also to microsoft.public.security.crypto)


.



Relevant Pages

  • Re: System.Text.Encoding help ????
    ... When converting arbitrary binary data like an encryption key or hash to/from ... When converting a string object to binary for encryption, etc., you need to ...
    (microsoft.public.dotnet.security)
  • Re: How to decrypt a string?
    ... converting a string to another string. ... No. Encryption works on binary data, and it's not safe to treat ...
    (microsoft.public.dotnet.framework)
  • Re: CR & Tab in VB 2005 Textbox
    ... Secondly the CStr is converting as you saw to a string with that value. ... I do this since I use both VB and C# and sometimes I need to use code and if I use the Dot.Net functions provided by the objects rather than the VB it is easier to convert since it is mostly getting rid of ending semi colons and changing square brackets into regular brackets. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Unicode String Parameters in DLLs
    ... > NOT Unicode, so you might have heard some stuff about that. ... > One thing to watch out for is if your DLL routine puts a zero byte at the ... > string ); it does not terminate the string. ... >> We are converting our application to work with Unicode. ...
    (microsoft.public.word.vba.general)
  • Re: error passing byte[] or strings of encrypted data to Web Service
    ... Converting Base64 should fix it. ... > this should be done automatically upon serialization by the proxy ... >> XML string is in fact a well-formed XML: ...
    (microsoft.public.dotnet.security)