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

  • Home
  • SEARCH
  • 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 330111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:39:03+00:00 2026-05-12T09:39:03+00:00

I want to store a byte array wrapped in a String object. Here’s the

  • 0

I want to store a byte array wrapped in a String object. Here’s the scenario

  1. The user enters a password.
  2. The bytes of that password are obtained using the getBytes() String method.
  3. They bytes are encrypted using java’s crypo package.
  4. Those bytes are then converted into a String using the constructor new String(bytes[])
  5. That String is stored, or otherwise passed around (NOT changed)
  6. The bytes of that String are obtained and they are different then the encoded bytes.

Here’s a snippet of code that describes what I’m talking about.

String s = "test123";
byte[] a = s.getBytes();
byte[] b = env.encrypt(a);
String t = new String(b);
byte[] c = t.getBytes();
byte[] d = env.decrypt(c);

Where env.encrypt() and env.decrypt() do the encryption and decryption. The problem I’m having is that the b array is of length 8 and the c array is of length 16. I would think that they would be equal. What’s going on here? I tried to modify the code as below

String s = "test123";
Charset charset = Charset.getDefaultCharset();
byte[] a = s.getBytes(charset);
byte[] b = env.encrypt(a);
String t = new String(b, charset);
byte[] c = t.getBytes(charset);
byte[] d = env.decrypt(c);

but that didn’t help.

Any ideas?

  • 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-12T09:39:04+00:00Added an answer on May 12, 2026 at 9:39 am

    It’s not a good idea to store binary data in a String object. You’d be better off using something like Base64 encoding, which is intended to make binary data into a printable string, and is completely reversible.

    In fact, I just found a public domain base64 encoder for Java: http://iharder.sourceforge.net/current/java/base64/

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

Sidebar

Ask A Question

Stats

  • Questions 166k
  • Answers 167k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the overloaded method GetObject(string, object[]) of the… May 12, 2026 at 1:25 pm
  • Editorial Team
    Editorial Team added an answer here's another, statistically sound good way: http://www.thebroth.com/blog/118/bayesian-rating May 12, 2026 at 1:25 pm
  • Editorial Team
    Editorial Team added an answer You can't have two base address with the same scheme… May 12, 2026 at 1:25 pm

Related Questions

I want to store a byte array wrapped in a String object. Here's the
I have been experimenting with using UUIDs as database keys. I want to take
Are there any issues with using a byte[] as a primary key in a
So I'm receiving data over a socket using a buffer (byte[]) of size 1024,
I thought I would find a solution to this problem relatively easily, but here

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.