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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:58:33+00:00 2026-05-30T05:58:33+00:00

I have to convert a string into binary using UTF-8, but i am unable

  • 0

I have to convert a string into binary using UTF-8, but i am unable to do that.
I have tried

String encodedName=URLEncoder.encode(name, "UTF-8");

but it doesn’t gave me the binary format, it just returned me the same string with slight changes, please help.

EDIT:

what i have to do:
I have a string suppose “HelloWorld”
I have to convert it to binary using “UTF-8” and then use SHA1 hashing algorithm and from this i will get the hashkey and this is what i need “a hashkey”.

I found this one for SHA1 hashing.

   public class AeSimpleSHA1 { 

    private  String convertToHex(byte[] data) { 
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) { 
            int halfbyte = (data[i] >>> 4) & 0x0F;
            int two_halfs = 0;
            do { 
                if ((0 <= halfbyte) && (halfbyte <= 9)) 
                    buf.append((char) ('0' + halfbyte));
                else 
                    buf.append((char) ('a' + (halfbyte - 10)));
                halfbyte = data[i] & 0x0F;
            } while(two_halfs++ < 1);
        } 
        return buf.toString();
    } 

    public  String SHA1(String text) 
    throws NoSuchAlgorithmException, UnsupportedEncodingException  { 
    MessageDigest md;
    md = MessageDigest.getInstance("SHA-1");
    byte[] sha1hash = new byte[40];
    md.update(text.getBytes("iso-8859-1"), 0, text.length());
    sha1hash = md.digest();
    return convertToHex(sha1hash);

    } 

} 
  • 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-30T05:58:34+00:00Added an answer on May 30, 2026 at 5:58 am

    It’s not really clear what you mean, but you’d usually use:

    byte[] data = name.getBytes("UTF-8");
    

    I’m not sure why you’ve used URLEncoder in your attempt – or what your “desired result” is.

    EDIT: Converting the binary data back to text so you can then call getBytes() on it in your SHA1 method makes no sense. Just change your hashing method do:

    public String hashSha1(byte[] data) throws NoSuchAlgorithmException, 
        UnsupportedEncodingException { 
      MessageDigest md = MessageDigest.getInstance("SHA-1");
      md.update(data, 0, data.length);
      return convertToHex(md.digest());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to convert an incoming String field into a BigDecimal field that would
I have an xml document object that I need to convert into a string.
I have string like \LESSING\root\cimv2:Win32_UserAccount.Domain=LESSING,Name=Admin How to convert it to LESSING\Admin using Framework?
For a project, I have to convert a binary string into (an array of)
I would like to convert a string into a node. I have a method
I have a piece of C# code that needs to convert a string array
Let's say I have an integer that I need to convert to a string
I have a string that I need to convert to the equivalent array of
I have binary data in a file that I can read into a byte
I am trying to convert UTF-8 string into UCS-2 string. I need to get

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.