Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Base64 And Utf8, Why Did It Worked?

Base64 UTF8 Encoding Triple DES encryption

  • Please log in to reply
4 replies to this topic

#1 Yonatan

Yonatan

    CC Regular

  • Member
  • PipPipPip
  • 37 posts
  • Location:Israel
  • Programming Language:C, Java, C++, C#, JavaScript, PL/SQL, Visual Basic .NET
  • Learning:Python, JavaScript

Posted 20 June 2012 - 02:24 PM

I hope this is the place for it, or maybe this should belong to the security forum?..

Anyway, I was working on a Triple-DES encryption, with a 16byte key, CBC mode, Zeros Padding.
I needed to write encrypted data to a txt file, and then read and decrypt it.

So I've used UTF8 Encoder to transfer strings and byte[] arrays, and it was all fine, until I wrote the cipher to the txt file.

When I read the contents it was suddenly corrupted, Ive wrote a byte[16] and read a byte[24].

This was fixed using the Convert.FromBase64 Method, using that Method Ive successfully read a byte[16] and decrypted it successfully.

So Im trying to figure out what just happend.

I do not have a good understanding of encodings and the Base64, Im trying to figure out why did the UTF8 Encoder couldn't read the data but the Base64 did.

Any Comments would be much appreciated.
  • 0

#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 20 June 2012 - 04:20 PM

i would like to know the details too, i will be reading up to someone explains :D
  • 0

#3 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 20 June 2012 - 09:11 PM

If it is possible to put the code here along with some encrypted text, please put it here. That will help us a lot to figure out an explanation for the situation you got.
  • 0

#4 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 20 June 2012 - 09:38 PM

The devil is in the details, which you have not provided.

However, UTF should not handle random bits or bytes. It is meant for encoding human readable language in to bit sequences that extends much further than ASCII.
  • You can either write binary to file directly (less portable, cannot view through text editor or online, but you know the size exactly. 16 bytes in = 16 bytes stored)

-or-
  • Use BASE64 (or hex) to encode the bytes as plaintext (ASCII!) where the size of the resulting text is 4*(nbytes/3) larger than the byte size. 16 bytes becomes 21, with padding characters = 24, weak, but apparent evidence your above result ended up as BASE64.

Thought: DES became weak in keysize and TripleDES stepped in, however it is inherently slower than others, as it performs its operation three times on itself to increase effective keysize.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#5 Yonatan

Yonatan

    CC Regular

  • Member
  • PipPipPip
  • 37 posts
  • Location:Israel
  • Programming Language:C, Java, C++, C#, JavaScript, PL/SQL, Visual Basic .NET
  • Learning:Python, JavaScript

Posted 22 June 2012 - 11:42 AM

Sry guys can't post the code since its not on this pc, but, I think Alexander answered my question.

Base64 is the encoding Ive needed to handle byte[] representation in a text file.

Thanks again!
  • 0





Also tagged with one or more of these keywords: Base64, UTF8, Encoding, Triple DES, encryption

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download