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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:37:22+00:00 2026-05-20T16:37:22+00:00

I have an issue with AES encryptio and decryption: I can change my IV

  • 0

I have an issue with AES encryptio and decryption: I can change my IV entirely and still I’m able to decode my data.

public static final byte[] IV = { 65, 1, 2, 23, 4, 5, 6, 7, 32, 21, 10, 11, 12, 13, 84, 45 };
public static final byte[] IV2 = { 65, 1, 2, 23, 45, 54, 61, 81, 32, 21, 10, 121, 12, 13, 84, 45 };
public static final byte[] KEY = { 0, 42, 2, 54, 4, 45, 6, 7, 65, 9, 54, 11, 12, 13, 60, 15 };
public static final byte[] KEY2 = { 0, 42, 2, 54, 43, 45, 16, 17, 65, 9, 54, 11, 12, 13, 60, 15 };
//public static final int BITS = 256;

public static void test()
{
    try
    {
        // encryption
        Cipher c = Cipher.getInstance("AES");
        SecretKeySpec keySpec = new SecretKeySpec(KEY, "AES");
        c.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(IV));

        String s = "Secret message";
        byte[] data = s.getBytes();

        byte[] encrypted = c.doFinal(data);

        String encryptedStr = "";
        for (int i = 0; i < encrypted.length; i++)
            encryptedStr += (char) encrypted[i];


        //decryoption
        Cipher d_c = Cipher.getInstance("AES");
        SecretKeySpec d_keySpec = new SecretKeySpec(KEY, "AES");
        d_c.init(Cipher.DECRYPT_MODE, d_keySpec, new IvParameterSpec(IV2));

        byte[] decrypted = d_c.doFinal(encrypted);
        String decryptedStr = "";
        for (int i = 0; i < decrypted.length; i++)
            decryptedStr += (char) decrypted[i];
        Log.d("", decryptedStr);

    }
    catch (Exception ex)
    {
        Log.d("", ex.getMessage());
    }
}

Any ideas what I’m doing wrong? How can I get 256 bit AES encryption (only change key to 32-byte long array?)

Encryption is a new topic for me so please for newbie friendly answers.

  • 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-20T16:37:23+00:00Added an answer on May 20, 2026 at 4:37 pm

    You aren’t specifying a cipher mode, so the provider is probably defaulting to Electronic Code Book mode (“ECB”) and ignoring the IV completely. You can verify this by comparing the cipher text produced by several runs of your program; I’m guessing that they are all identical.

    Cipher-block chaining (“CBC”) is commonly supported and widely used, but the right mode depends on your application.

    You aren’t specifying padding either, so the provider is picking a default. What the JCE calls “PKCS5Padding” is a common choice for symmetric ciphers.

    Instead of specifying “AES” as the algorithm, provide a complete specification including algorithm, mode, and padding, like “AES/CBC/PKCS5Padding”.

    You don’t have to specify the AES key size in the Cipher name; it is inferred from the size of the key that you use to initialize the cipher.

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

Sidebar

Related Questions

I have issue with displaying AlertDialog from Service. I am able to display custom
Have an issue with the following array... I can't navigate it using $arrayname[0]... it
Hi everybody I'm a beggining with extjs and I have issue with change /
I have an issue with the static method in ASP.NET. I created the Singleton
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue using the PEAR libraries on Windows from PHP . Pear
We have an issue related to a Java application running under a (rather old)
We have an issue on our page whereby the first time a button posts
I have some issue with a Perl script. It modifies the content of a
I have an issue with using AWK to simply remove a field from a

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.