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

The Archive Base Latest Questions

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

I have a hex string after RSA encryption. When I convert it to a

  • 0

I have a hex string after RSA encryption. When I convert it to a byte[], the RSA decryption gives javax.crypto.BadPaddingException: Blocktype mismatch: 0

I am using this method for conversion (got it on Stack overflow itself)

public static byte[] hexStringToByteArray(String data) {
    int k = 0;
    byte[] results = new byte[data.length() / 2];
    for (int i = 0; i < data.length();) {
        results[k] = (byte) (Character.digit(data.charAt(i++), 16) << 4);
        results[k] += (byte) (Character.digit(data.charAt(i++), 16));
        k++;
    }
    return results;
}

Any suggestions please.

  • 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-26T06:27:40+00:00Added an answer on May 26, 2026 at 6:27 am

    The encryption method requires the input to be a fixed-length; you’re going to have to add padding to the required length in order to avoid this exception. This size will depend on the key size.

    EDIT: There is also a potential bug in your iteration of data: If its length is not divisible by two then the second i++ will cause an IndexOutOfBoundsException. You are better off incrementing i by 2 in the for loop and using [i] and [i+1] when accessing the data:

    for (int i = 0; i + 1 < data.length(); i += 2, k++)
    {
        results[k] = (byte) (Character.digit(data.charAt(i), 16) << 4);
        results[k] += (byte) (Character.digit(data.charAt(i + 1), 16));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hex string,st=9e. I need to convert it into byte and insert
I have a hex string and i want to convert it utf8 to insert
i have a very long hex string in a byte array and I would
I have a large hex string abcdef... and I want to convert it to
How would I convert a file to a HEX string using Python? I have
I have a Hex String 40 that i would like to convert to its
Can we convert a hex string to a byte array using a built-in function
I have a long sequence of hex digits in a string, such as 000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44
Let's say that I have a string 5a . This is the hex representation
I have a twenty byte hex hash that I would like to store in

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.