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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:02:16+00:00 2026-05-13T14:02:16+00:00

I am able to encrypt with AES 128 but with more key length it

  • 0

I am able to encrypt with AES 128 but with more key length it fails.

code using AES 128 is as below.

import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;

/**
* This program generates a AES key, retrieves its raw bytes, and
* then reinstantiates a AES key from the key bytes.
* The reinstantiated key is used to initialize a AES cipher for
* encryption and decryption.
*/

public class AES {

 /**
 * Turns array of bytes into string
 *
 * @param buf   Array of bytes to convert to hex string
 * @return  Generated hex string
 */
 public static String asHex (byte buf[]) {
  StringBuffer strbuf = new StringBuffer(buf.length * 2);
  int i;

  for (i = 0; i < buf.length; i++) {
   if (((int) buf[i] & 0xff) < 0x10)
    strbuf.append("0");

   strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
  }

  return strbuf.toString();
 }

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

   String message="This is just an example";

   // Get the KeyGenerator

   KeyGenerator 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");

   cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

   byte[] encrypted =cipher.doFinal("welcome".getBytes());
   System.out.println("encrypted string: " + asHex(encrypted));

   cipher.init(Cipher.DECRYPT_MODE, skeySpec);
   byte[] original =
     cipher.doFinal(encrypted);
   String originalString = new String(original);
   System.out.println("Original string: " +
     originalString + " " + asHex(original));
  }
}
  • 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-13T14:02:16+00:00Added an answer on May 13, 2026 at 2:02 pm

    Java 1.4 ships with a Strong JCE policy file. You need to install the Unlimited Strength policy to use AES key length beyond 128.

    See this,

    http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html

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

Sidebar

Related Questions

I have a CryptoAPI code to encrypt\ decrypt given data using AES-128 and a
I would like to encrypt strings of 1500-2500 characters using an Asymmetric Key. It
I'd like to AES-128 encrypt a string in Delphi with a password. I'd like
I am written an algorithm to encrypt and decrypt file using AES. I am
I'm looking to encrypt some data using multiple ciphers (ie, AES, Serpent, Twofish...), and
Possible Duplicate: Java AES Encrypt Entire String Im having problems with the conversions back
Can anybody point me in the right direction to be able to encrypt a
I want a form where user can change password. I am able to encrypt
Hi I have been able to extract a VARCHAR to a date using string_to_date
I am able to read emails in from Microsoft Exchange using an IMAP Client

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.