Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:30:42+00:00 2026-06-17T20:30:42+00:00

For academic purposes, I am working on a small encryption-based application using java and

  • 0

For academic purposes, I am working on a small encryption-based application using java and java crypto. That said, I generally work in C or C++ (where this happens to be very easy) so I apologize if this is an obvious issue. So my issue comes when I want to decrypt information. The problem is not so much related to using crypto or anything, but, in fact, retrieving my initialization vector properly. For now I have a plaintext file with the following format new-line/colon delimited (yes, this is insecure but it’s an academic exercise – obviously the key file would not be in plaintext in the real world)

password:salt:<IV>

Where <IV> is the initialization vector. I decided to write out the initialization vector directly in binary format. Now I here is where my problem begins. I can write out the data properly (verified using hexdump), but it does not seem that it is being properly read back into the program. For instance, consider a counter value of

00 18 C0 98 (decimal: 1622168)

This value is correctly written out. However, when I try to read it in, this value is all wrong. I suspect this is a result of BufferedReader.readLine(). I simply read this line and write it out to another file and this value is then changed to

BD EF BF BD (decimal: who cares, very wrong...)

But the ASCII values (password and salt) remain intact as well as the colon delimiters. The initialization vector binary is all the gets scrambled.

What I am trying to do is this:

BufferedReader reader = new BufferedReader(new FileReader(f));
String last  = null;
String parse = null;
while((last = reader.readLine()) != null) {
    parse = last;
}
reader.close();
int offset = // A few indexOf() statements to find the positon;
byte[] iv  = parse.substring(offset).getBytes();

At this point, iv.length > 16 (using 128-bit AES) which is already wrong. So I am not entirely sure how I can accomplish this ASCII-binary mix (perhaps it is bad design to begin with). Part of my issue is that char != byte in Java and I cannot simply read everything in as byte’s if I want to read a full line (using readLine() anyway). But is there anyway to get around this issue? Since I want the full line, but I also want to extract binary from this line.

Additionally, I have also tried a direct conversion

for(int i = 0 ; i < 16 ; ++i)
  iv[i] = (byte)parse.charAt(offset + i);

But this does not work either. The other code (getBytes()-based) was working on my personal machine with java version "1.6.0_37", but the deployment environment is using java version "1.6.0_33" where this is failing. Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:30:43+00:00Added an answer on June 17, 2026 at 8:30 pm

    What is a line of binary data? How do you know which 0x0A is data and which is a newline?

    The point is BufferedReader is meant for reading text, not arbitrary data! It will treat all of your data as text. It will also attempt to convert your binary to text using some encoding, which will of course mangle your data.

    A better method would be to either:

    • Not write any of your data as binary, and rely on newlines or some other delimiter. (e.g. keep using BufferedReader.readLine())
    • Write all of your data as binary, and either make each record in your file of a fixed length, or come up with some more complicated delimiter scheme. (e.g. just use FileInputStream.read(byte[]))
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a small academic research about extremely long and complicated functions in
This is for academic purposes, please no responses of why would you want to
For academic purposes, our essential team (me and a friend) is programming a tile-based
I writing a small (relatively) application on haskell in academic purpose. I'm implementing a
This is a purely academic question, but what's the difference between using == and
Quite an academic question this - I've had it remarked that a class I've
This is an academic exercise, I'm new to Reactive Extensions and trying to get
This question is mostly academic. I ask out of curiosity, not because this poses
This is really just sort of an academic question, I'm just curious to know
This may seem to be an academic question, but still I would be very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.