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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:42:16+00:00 2026-05-31T01:42:16+00:00

In my project i am working on AES encryption and Decryption.i have used this

  • 0

In my project i am working on AES encryption and Decryption.i have used this algorithm to encrypt and decryption a string and storing the string in the sq-lite database.Now i get that encrypted key from database and try to decryption it but it shows an Exception (pad Block corrupted).I am converting the Encrypted string into the bytes by using

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

and getting the correct Bytes but while converted into the String it shows ‘pad block corrupted’.
Thanks in advance.really appreciate if find answer.
my code is

dh=new data_helper(Resy.this);
        mac_db=dh.getData();

//        getdata=mac_db.toString();

        KeyGenerator kgen;
        try {
            kgen = KeyGenerator.getInstance("AES");

             kgen.init(128); // 192 and 256 bits may not be available

  // Generate the secret key specs.
                SecretKey skey = kgen.generateKey();
                byte[] raw = skey.getEncoded();

                SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");


                // Instantiate the cipher

                Cipher cipher = Cipher.getInstance("AES");
                         getdata=mac_db.toString();
//              byte g1[]=getdata.getBytes();
//              System.out.println(g1);

        byte b[]=hexStringToByteArray(getdata);
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        byte[] m1=cipher.doFinal(b);   // here pad block corrupt exception came.
                String originalString_mac = new String(original_macadress);
                Toast.makeText(getApplicationContext(),"Original : " +originalString_mac + " " + asHex(original_macadress) , Toast.LENGTH_LONG).show();
  • 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-31T01:42:18+00:00Added an answer on May 31, 2026 at 1:42 am

    you have to do Base64 encoding of it to get proper AES encrypt/decrypt to work.

    Do it as follows.

    For encrytion : Original String –> Aes encryption > base64 encode —>(encrypted string)

    For decryption : encrypted string —> base64 decode > aes decryption —> Original String

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

Sidebar

Related Questions

I have a bonita open studio project working great. Now, I don't know how
I'm working a small project, using AES encryption and wanted to use it in
I have a new project working with an existing oracle database. I've always been
I have started using Linq to SQL for a project im working on and
I working on project and have problem with threading and update of UI. I
I have a view based project working with a UINavigationController. The RootViewController performs operations
I have spent hours trying to get my project working and I just can't
I Currently perform a large amount of encryption/decryption of text in c# using AES.
I've been trying to get an existing project working on local copy but have
Have been trying to get integration testing working with my seam project and the

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.