Cheers, Martijn,
Twitter.
Martijn Verburg wrote:this thread might be of some help.
Cheers, Martijn,
Twitter.
Martijn Verburg wrote:Without knowing anything about this area, have you tried:
1.) Getting the length of the input (seeing that's what it's complaining about).
2.) Ensuring that the encoding is consistent throughout (remember some encoding schemes use 2-bytes or more per character, some use 1). You need to make sure it's consistent across each read/write.
That's off the top of my head anyhow.
Cheers, Martijn,
Twitter.
Paul Clapham wrote:I'm not sure the getting the MAC address is as easy as you think it is. For example my computer has two of them (one for the place where you plug in the cable connecting you to the LAN and another for my wireless connection). I don't think that's unusual for computers these days. Which one are you going to use? And if my LAN is down and I connect via wireless, do I fail the licensing check?
A couple of things:
1.) I notice you use "8859_1" to write but a different encoding to read. You'll want to be consistent there.
2.) Line endings, are any of those being written? (I don't think the write() method does this, but perhaps some are being inserted manually).
3.) Oh, how many iterations is the write() being called?
Paul Clapham wrote:Normally when you use encryption, you generate an array of bytes. These bytes are just numbers and don't represent any text, so writing them somewhere as text (e.g. with a Writer of any kind) is a mistake and will just lead to problems. Likewise trying to read them with a Reader won't work either.
If you want a text representation of those bytes, then Base64-encoding them or hex-encoding them would do that. You can then write the result of those encodings to a licence file, and read them back and reverse the encoding to get the bytes back.
Or you could just write the bytes to a file (with a FileOutputStream) and then read them back as bytes (with a FileInputStream).
Paul Clapham wrote:There aren't any "lines" in a file where you just write a bunch of bytes. Your original code (way back there) appeared to be using a Reader, which doesn't make sense for bytes.
Paul Clapham wrote:Um, you're still using a Reader to read data that isn't text. Don't do that. Like I said before, just read the bytes.
From your code it looks like you're hung up on the idea of lines in your encrypted data. Don't do that. In fact right now you're dropping the line endings from the plaintext and not encrypting them. Don't do that either. In fact, don't treat the input data as text either. Read it as bytes, encrypt the bytes, and write the encrypted bytes to the output. To decrypt, read the bytes, decrypt them, and write the decrypted bytes to the output.
Paul Clapham wrote:What "line"? Don't treat anything as if it had lines. Not the plaintext nor the ciphertext. It's all just a series of bytes.
Something must be done about this. Let's start by reading this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|