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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:34:33+00:00 2026-06-08T01:34:33+00:00

I am working on a project where I need to send verification link to

  • 0

I am working on a project where I need to send verification link to user. So encrypted his username using AES encrytion. My code works fine, i.e, encryption and decrytpion are working fine but only in the program when I tested it. I encrypted a string and then decrypted it. It works fine ‘locally’.

The problem is, when I send email with activation link and click on it, it gives me error:

javax.crypto.BadPaddingException: Given final block not properly padded

My code is as shown below:

public class AES {

private static final String algo="AES";
private static final byte[] keyValue= 
        new byte[]{somekey};

private static Key generateKey() throws Exception{

    Key key= new SecretKeySpec(keyValue, algo);

    return key;
}

public static String encrypt(String  email) throws Exception{

    Key key=generateKey();
    Cipher c=Cipher.getInstance(algo);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encVal=c.doFinal(email.getBytes());
    String encryptedEmail= new BASE64Encoder().encode(encVal);

    return encryptedEmail;
}

public static String decrypt(String encryptedEmail) throws Exception{

    Key key=generateKey();
    Cipher c=Cipher.getInstance(algo);
    c.init(Cipher.DECRYPT_MODE, key);

    byte[] decodeEmail= new BASE64Decoder().decodeBuffer(encryptedEmail);
    byte[] decodedEmail=c.doFinal(decodeEmail);

    String decryptedEmail= new String(decodedEmail);

    return decryptedEmail;
    }

}

  • 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-06-08T01:34:35+00:00Added an answer on June 8, 2026 at 1:34 am

    I got it to run using the Base64 encoder/decoder of Bouncy Castle libraries, no problem at all. Check your input/output and use a valid base 64 encoder/decoder, not a Sun internal one with unspecified input/output.

    Warning: as you use unspecified character encoding it will use the platform specific one, so your input/output may be different on separate systems. Try and use Charset.forName(“UTF8”) for the most compatible character encoding (in the String constructor and toBytes method).

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

Sidebar

Related Questions

I am working on a project and I need to save user configuration. The
I'm working on a project where I need to create a link that when
Im working on a small project which I need to send a couple of
i'm working in a project where i need to read some values and send
I am working on a distributed processing project. I need to send my composite
I'm working on a project in PHP (5.3.1) where I need to send a
I'm currently working on a project where I need to send an email to
I'm working in a project that need to get SVD (Single Values Decomposition) for
I was working on a project and I need to read a row in
I am working on a project where I need to automate some workflows 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.