in reply to Re^2: AES Interoperability between Perl and C#
in thread AES Interoperability between Perl and C#

There's two common ways of storing a string.

1) NUL-terminated.

The end of the string is marked by the first occurance of a NUL character.

Pro: The string can be of any length.
Con: The string cannot contain NULs.

2) PASCAL string.

Named after the programming language. The length of the string is stored along with the string itself.

Pro: The string can contain any character.
Con: The size of the length field limits the size of the string.

Thelonius chose the latter. And in this case, the limit on the string length is (2^32)-1 (over 2 billion) since he's using a 32 bit signed int for the length field.

  • Comment on Re^3: AES Interoperability between Perl and C#

Replies are listed 'Best First'.
Re^4: AES Interoperability between Perl and C#
by jpfarmer (Pilgrim) on Nov 17, 2005 at 22:32 UTC

    So by commenting that out, I'm forcing the NUL-terminated mode?

      It depends on what you are encrypting. If you are encrypting many thing, you need a way of telling how long each thing is so you can seperate them once the ciphertext is decrypted.

      If you're encrypting more than just a string, You'll need to add a NUL if you remove the length. You have to use one or the other (or some other alternative) in order to know where the string ends and the next thing in the plaintext start.

      If the ciphertext only contains the string, you don't need either mechanism since the length of the string will be deduced by the length of the ciphertext.