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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:00:30+00:00 2026-05-13T07:00:30+00:00

I am reading about encryption and having a lot of difficulty understanding these 3

  • 0

I am reading about encryption and having a lot of difficulty understanding these 3 Java statements of an encryption program.

    cipher = Cipher.getInstance("AES");

    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

    encrypted = cipher.doFinal(str.getBytes())

Can somebody help?

  • 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-13T07:00:30+00:00Added an answer on May 13, 2026 at 7:00 am
    cipher = Cipher.getInstance("AES");
    

    Get a Cipher object that can encrypt/decrypt using the AES algorithm. Java’s cryptography code is a bit weird – instead of directly creating objects, you generally use a getInstance call with a String argument. (Note that “cipher” means “way of encrypting something”.)

    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    

    Tell the cipher that you would like to encrypt something (Cipher.ENCRYPT_MODE), and give it the encryption key skeyspec.

    encrypted = cipher.doFinal(str.getBytes())
    

    The way ciphers work is that you feed them chunks of byte data using the update method, which causes the cipher to accumulate the encrypted data within itself. For the final block of data, doFinal is used, which tells the cipher that the encryption process is done. A different method is needed because the cipher often has to pad out the data returned to a particular length. doFinal then returns the final bit of encrypted information.

    However, if there is a single readily available chunk of data, you can just call doFinal and it will give you all the encrypted bytes at once. But this explains why the method is called doFinal, not say, “process“.

    So in summary, the code above creates an AES encryption engine, gives it an encryption key, then uses it to encrypt the String str into the byte array encrypted.

    Note that cryptography is very tricky business and very easy to get wrong. There’s all kinds of things you need warning about that I haven’t touched on because my wrists hurt now. So I would heavily recommend you get a copy of Beginning Cryptography with Java – it’s where I learned to understand this stuff.

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

Sidebar

Related Questions

I am doing a simple AES encryption in Java: Cipher cipher = Cipher.getInstance(AES); cipher.init(Cipher.ENCRYPT_MODE,
So I've been reading a lot about encryption in PHP. So much that I
I am reading about cryptography I was thinking about these properties of AES (that
I am reading about Hill Cipher encryption algorithm, from the wikipedia. I see that
I've been reading a little about encryption recently and am interested in protecting a
There seems to be a lot of hype about asymmetric Public Key encryption. RSA,
I've been reading up about ID-based encryption , but can't find any implementations (the
Ok, so I've been reading (a lot!) about security and the whole deal about
I've been reading about encryption and decryption of certain parts of the web.config for
When reading about volume rendering, I see voxel rendering is mentioned a lot. I

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.