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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:26:38+00:00 2026-05-27T11:26:38+00:00

image is the string of an image file . I have code as follows

  • 0

image is the string of an image file .

I have code as follows in C#:

Convert.ToBase64String(image);

and code as follows in Java:
org.apache.commons.codec.binary.Base64.encodeBase64(image.getBytes())

The result is different.

Somebody says its because

  • Java byte : -128 to 127

  • C# byte : 0 to 255

But how can I fix this? How can I implement C#’s Convert.ToBase64String() in Java?
I need the same result as in C# by using Java.

  • 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-27T11:26:39+00:00Added an answer on May 27, 2026 at 11:26 am

    You’re base64 encoding a string? What do you want that to do? You first need to convert the string to a sequence of bytes, choosing an encoding such as UTF-8 or UTF-16.

    My guess is that you managed to use different encodings on both sides. Java’s String.GetBytes() uses the default charset (Probably something like Latin1 on western windows versions). For C# you didn’t post the relevant code.

    To fix this, choose an encoding and use it explicitly on both sides. I recommend using UTF-8.
    On the Java side you should use the correct method for encoding, so you don’t end up with “modified UTF-8”, but since I’m not a java programmer, I don’t know which methods output modified UTF-8. I think it only happens if you abuse some internal serialization method.

    signed vs. unsigned bytes should not be relevant here. The intermediate byte buffer will be different, but the original string, and the base64 string should be identical on both sides.

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

Sidebar

Related Questions

Is there a way to convert a HTML string into a Image .tiff file?
public Image Base64ToImage(string base64String) { // Convert Base64 String to byte[] byte[] imageBytes =
I have source code: private Image getImage(String path, ClassLoader loader) { InputStream image =
I have here this code. I want it to first display an image file
Suppose I have string Name and Image Photo as properties of a class in
I have a string in my database that represents an image. It looks like
I'm currently having trouble creating an image from a binary string of data in
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
I have a collection of string. I want to create an image out of
I am attempting to insert an image into a rich text file. I have

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.