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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:23:15+00:00 2026-05-11T22:23:15+00:00

I have an SHA-1 byte array that I would like to use in a

  • 0

I have an SHA-1 byte array that I would like to use in a GET request. I need to encode this. URLEncoder expects a string, and if I create a string of it and then encode it, it gets corrupt?

To clarify, this is kinda a follow up to another question of mine.
(Bitorrent Tracker Request) I can get the value as a hex string, but that is not recognized by the tracker. On the other hand, encoded answer mark provided return 200 OK.

So I need to convert the hex representation that I got:

9a81333c1b16e4a83c10f3052c1590aadf5e2e20

into encoded form

%9A%813%3C%1B%16%E4%A8%3C%10%F3%05%2C%15%90%AA%DF%5E.%20
  • 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-11T22:23:15+00:00Added an answer on May 11, 2026 at 10:23 pm

    Question was edited while I was responding, following is ADDITIONAL code and should work (with my hex conversion code):

    //Inefficient, but functional, does not test if input is in hex charset, so somewhat unsafe
    //NOT tested, but should be functional
    public static String encodeURL(String hexString) throws Exception {
      if(hexString==null || hexString.isEmpty()){
         return "";
      }
      if(hexString.length()%2 != 0){
        throw new Exception("String is not hex, length NOT divisible by 2: "+hexString);
      }
      int len = hexString.length();
      char[] output = new char[len+len/2];
      int i=0;
      int j=0;
      while(i<len){
          output[j++]='%';
          output[j++]=hexString.charAt(i++);
          output[j++]=hexString.charAt(i++);
      }
      return new String(output);
    }
    

    You’ll need to convert the raw bytes to hexadecimal characters or whatever URL-friendly encoding they are using. Base32 or Base64 encodings are possible, but straight hexadecimal characters is the most common. URLEncoder is not needed for this string, because it shouldn’t contain any characters that would require URL Encoding to %NN format.

    The below will convert bytes for a hash (SHA-1, MD5SUM, etc) to a hexadecimal string:

    /** Lookup table: character for a half-byte */
        static final char[] CHAR_FOR_BYTE = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
             /** Encode byte data as a hex string... hex chars are UPPERCASE*/
             public static String encode(byte[] data){
                 if(data == null || data.length==0){
                     return "";
                 }
                 char[] store = new char[data.length*2];
                 for(int i=0; i<data.length; i++){
                     final int val = (data[i]&0xFF);
                     final int charLoc=i<<1;
                     store[charLoc]=CHAR_FOR_BYTE[val>>>4];
                     store[charLoc+1]=CHAR_FOR_BYTE[val&0x0F];
                 }
                 return new String(store);
             }
    

    This code is fairly optimized and fast, and I am using it for my own SHA-1 byte encoding. Note that you may need to convert uppercase to lowercase with the String.toLowerCase() method, depending on which form the server accepts.

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

Sidebar

Ask A Question

Stats

  • Questions 136k
  • Answers 136k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer "Non-final" is a keyword here. You may have another class… May 12, 2026 at 7:10 am
  • Editorial Team
    Editorial Team added an answer Probably what you want is some version of itoa. Here… May 12, 2026 at 7:10 am
  • Editorial Team
    Editorial Team added an answer Reviewing the first diagram as the Logical model, typically the… May 12, 2026 at 7:10 am

Related Questions

I have to verify the signature on a file that may be as large
<machineKey validation=SHA1 validationKey=<64-byte key> What exactly does the validationKey do? Say I create a
I have a set of bytes I want to apply an sha1 hash to.
I have a website where users can upload their files; these are stored on

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.