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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:08:16+00:00 2026-05-26T05:08:16+00:00

Possible Duplicate: Java AES Encrypt Entire String I’ve run into a small problem. For

  • 0

Possible Duplicate:
Java AES Encrypt Entire String

I’ve run into a small problem. For some reason, I can’t decrypt some strings using the same method that I encrypt them. For example, I’m using this code for decrypting:

        SecretKeySpec key = new SecretKeySpec(salt.getBytes(), "AES");
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");
    cipher.init(Cipher.DECRYPT_MODE, key);
    String result = new String(cipher.doFinal(message));

    System.out.println("Decrypted:" + result);

Anyway, when the salt is “1231231231231231” and the message that im trying to decrypt is “read”. I get this error:

Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly padded

But the encryptor (which works the same way) says the encrypted value is

I¡?Þd↨Ú#à, 7êLO* 

How can I fix this or avoid the user from inputting such strings? Thansk

  • 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-26T05:08:17+00:00Added an answer on May 26, 2026 at 5:08 am

    Solution: don’t store it in a string.

    Your call to Cipher.doFinal should be stored in a byte array (byte[]), and your input to the decryption should likewise be a byte array. If you’re taking a String input, use .getBytes(); when you’re creating the String for an output, use new String(myArray)

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

Sidebar

Related Questions

Possible Duplicate: Java AES Encrypt Entire String Im having problems with the conversions back
Possible Duplicate: Generate MD5 hash in Java Can some one tell me how to
Possible Duplicate: Java string comparison? I have encounter the following problem, I have an
Possible Duplicate: java operator ++ problem public class A { public static void main(String[]
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
Possible Duplicate: Java operator overload In c++, we can perform the operator overloading. But
Possible Duplicate: How can I convert my java program to an .exe file ?
Possible Duplicate: java String concatenation How to Improve performance of this chunk of code
Possible Duplicate: Java Generics To be more specific, whats the role of the <String>
Possible Duplicate: Best Java obfuscator ? Well, I'm planning on releasing a Jar into

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.