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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:31:33+00:00 2026-06-09T20:31:33+00:00

Possible Duplicate: Why is char[] preferred over string for passwords? I read somewhere that

  • 0

Possible Duplicate:
Why is char[] preferred over string for passwords?

I read somewhere that storing a sensitive key as a char[] rather than a String is better because the latter can be found in the memory. It also makes a little sense because of JPasswordField’s getText() method being Deprecated.

Is this true?

  • 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-09T20:31:34+00:00Added an answer on June 9, 2026 at 8:31 pm

    Once you are done using the password in a char[] you can always overwrite it with 0’s or random values. However, you can’t do that with String objects because they are immutable objects in Java and the strings will remain alive until the garbage collector kicks in and clears it.

    Here is an interesting note at http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html

    In this example, we prompt the user for a password from which we derive an encryption key.

    It would seem logical to collect and store the password in an object of type java.lang.String. However, here’s the caveat: Objects of type String are immutable, i.e., there are no methods defined that allow you to change (overwrite) or zero out the contents of a String after usage. This feature makes String objects unsuitable for storing security sensitive information such as user passwords. You should always collect and store security sensitive information in a char array instead.

    For that reason, the javax.crypto.spec.PBEKeySpec class takes (and returns) a password as a char array.

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

Sidebar

Related Questions

Possible Duplicate: Last but one Char in vb.net String How do I find the
Possible Duplicate: What is the difference between char a[] = “string” and char *p
Possible Duplicate: C++ char* vs std::string Is there any advantage to using char*'s instead
Possible Duplicate: how to copy char * into a string and vice-versa I have
Possible Duplicate: Why is this C code causing a segmentation fault? char* string =
Possible Duplicate: C++ convert int and string to char* Hello, i am making a
Possible Duplicate: Modifying C string constants? Pointer to const char vs char array vs
Possible Duplicate: C++ deprecated conversion from string constant to 'char*' I want to pass
Possible Duplicate: RegEx to make sure that the string contains at least one lower
Possible Duplicate: Convert std::string to const char* or char* is there any to get

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.