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 7609463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:10:40+00:00 2026-05-31T01:10:40+00:00

I am trying to do such conversions, but i have a little problem. Let’s

  • 0

I am trying to do such conversions, but i have a little problem.

Let’s say i have a following String:

String in = "1234567890123456";

Then I convert it to ByteArrayInputStream like this:

ByteArrayInputStream bais = new ByteArrayInputStream(in.getBytes("UTF-8"));

I also have:

ByteArrayOutputStream baos = new ByteArrayOutputStream();

Then I do my encryption:

ch.encrypt(bais, baos);

So now I have my “output” in baos. When i do such thing:

byte[] b2 = baos.toByteArray();
int[] i2 = toUnsignedIntArray(b2);
writeIntegersAsHex(i2);

where (I know it is not the most elegant way but it’s only for testing):

 public static void writeIntegersAsHex(int[] integers) {
    int height = integers.length;
    for (int i = 0; i < height; i++) {
        System.out.print(Integer.toHexString(integers[i]) + ",");
    }
    System.out.println("");
}

I get such output:

d1,68,a0,46,32,37,25,64,67,71,17,df,ee,ef,2,12,

And that output is correct, because when I process file that contains the same string as in that output is the same. But I can’t get a proper string from baos.

Please don’t ask me why am i doing it this way, because it was not my call. I am a student and this is one of the excersises.

The algorithm (btw it’s aes128) works ok, with files but i can’t get string to inputstream and outputstream to string work properly.

  • 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-05-31T01:10:41+00:00Added an answer on May 31, 2026 at 1:10 am

    But I can’t get a proper string from baos.

    At this point your output is just arbitrary binary data. It’s not encoded text – it’s just a bunch of bits.

    To convert that to a sensible string which will let you convert it back to the original bytes, you should probably use either hex or base64. There’s a public domain base64 library which works well in my experience, or plenty of other alternatives (for both base64 and hex).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
I'm trying to store a url such as: http://localhost/pro_print/index.php#page=home in a variable, but I
I'm encountering the following problem - I have simple GWT overlay types, and I'm
I have a string array as such: NSArray *names; names = [NSArray arrayWithObjects: @FirstList,
I have been trying to return an ARABIC string from a JNI call. The
I am trying to use the STL function for_each to convert a string into
I am trying to convert a CString to an unsigned int. I have looked
I have a feeling my problem is a bit strange, but here goes... I
I'm trying to compile such code: #include <iostream> using namespace std; class CPosition {
I'm thinking of trying a VCS such as subversion , to manage my next

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.