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

  • Home
  • SEARCH
  • 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 7939151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:00:52+00:00 2026-06-03T23:00:52+00:00

I am using the following LINK for encryption and tried it with Strings and

  • 0

I am using the following LINK for encryption and tried it with Strings and it worked. However, since I am dealing with images, I needed the encryption/decryption process to happen with byte arrays. So I modified the code in that link to the following:

public class AESencrp {

    private static final String ALGO = "AES";
    private static final byte[] keyValue = 
    new byte[] { 'T', 'h', 'e', 'B', 'e', 's', 't',
'S', 'e', 'c', 'r','e', 't', 'K', 'e', 'y' };

    public static byte[] encrypt(byte[] Data) throws Exception {
        Key key = generateKey();
        Cipher c = Cipher.getInstance(ALGO);
        c.init(Cipher.ENCRYPT_MODE, key);
        byte[] encVal = c.doFinal(Data);
        //String encryptedValue = new BASE64Encoder().encode(encVal);
        return encVal;
    }

    public static byte[] decrypt(byte[] encryptedData) throws Exception {
        Key key = generateKey();
        Cipher c = Cipher.getInstance(ALGO);
        c.init(Cipher.DECRYPT_MODE, key);

        byte[] decValue = c.doFinal(encryptedData);
        return decValue;
    }

    private static Key generateKey() throws Exception {
        Key key = new SecretKeySpec(keyValue, ALGO);
        return key;
    }

and the checker class is:

public class Checker {

    public static void main(String[] args) throws Exception {

        byte[] array = new byte[]{127,-128,0};
        byte[] arrayEnc = AESencrp.encrypt(array);
        byte[] arrayDec = AESencrp.decrypt(arrayEnc);

        System.out.println("Plain Text : " + array);
        System.out.println("Encrypted Text : " + arrayEnc);
        System.out.println("Decrypted Text : " + arrayDec);
    }
}

However my output is:

Plain Text : [B@1b10d42
Encrypted Text : [B@dd87b2
Decrypted Text : [B@1f7d134

So the decrypted text is not the same as plain text. What should I do to fix this knowing that I tried the example in the original link and it worked with Strings?

  • 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-03T23:00:54+00:00Added an answer on June 3, 2026 at 11:00 pm

    What you’re seeing is the result of the array’s toString() method. It’s not the content of the byte array. Use java.util.Arrays.toString(array) to display the content of the arrays.

    [B is the type (array of bytes), and 1b10d42 is the hashCode of the array.

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

Sidebar

Related Questions

I tried using the answer posted by Chirag and Venkatesh in the following link:
I am customizing UItextField for local currency symbol and comma, using following link :
I'm using Fancybox 1.3.4 with ASP.NET MVC 3. I have following link : <a
I'm currently using the following code to append a X link to each element
I have been using the following to add a dynamic link on a page
I am using bitlyj snapshot jar to shorten URLs from the following link. http://code.google.com/p/bitlyj/downloads/list
I am using Fancybox. When the following link is clicked the modal window opens
I am learning expression blend using the following link http://visitmix.com/labs/rosetta/EyesOfBlend/DataTemplates/ It is a very
I am doing an application where I am using the following link http://iosdevelopertips.com/cocoa/date-formatters-examples-take-3.html to
I am trying to open the window pictured in the following link using 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.