Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: AES Interoperability between Perl and C#

by jpfarmer (Pilgrim)
on Nov 17, 2005 at 22:03 UTC ( [id://509608]=note: print w/replies, xml ) Need Help??

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

Thank you for the code sample. One part I'm curious about in the C# segment. Do you understand the significance of this block?

encLen = BitConverter.GetBytes( IPAddress.HostToNetworkOrder(toEncrypt.Length)); csEncrypt.Write(encLen, 0, encLen.Length);

When I comment it out, the encrypted string becomes much shorter, but it's still decryptable.

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

    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.

      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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://509608]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-07-15 08:12 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.