Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Simple string encrypt and decrypt

  1. #1
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Simple string encrypt and decrypt

    Hi

    I am wanting to encrypt a string which contains a password, the encrypted string will be saved within an external .txt file so it would be best for it to be encrypted.

    Has anyone used something similar?

    The encryption does not have to be really complex but enough to through a user off if they look at the text.

    I would be looking for the simplest solution as possible and dont want to be writing complex classes to handle the encryption and decryption of a single string.


    I was thinking about using a 'Shift' encryption which basically moves the letter along the alphabet by a defined amount, e.g. the letter 'A' with a shift of 6 would equal a 'G'. But this may be too simple?


    Thanks


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Simple string encrypt and decrypt

    How critical is the data being protected by the password? If there is a password, it must be important.

    For important data, the simple Caesar Cipher you describe is not good enough. There are many "simple" ciphers, but all can be broken, some more easily than others. Review the Cipher class and work a few tutorials. I started with this one, but there are others.

  3. #3
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Simple string encrypt and decrypt

    Hi Greg

    Thanks for the info, the data is not really critical, the password is for the database in which it is held so really it should have half decent encryption applied to the password.

    I looked at the tutorial you posted and looks like it would do all that I require, however how would this work as I am guessing I would need to store the 'secret key' as well as the encrypted text so I could decrypt the text. the 'secret key' seems to be a SecretKey object so how would I store the secret key?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Simple string encrypt and decrypt

    Key Management/Key Storage is (IMO) the harder topic, but start simple and get more complicated as the security requirements dictate and as you get smarter. By starting simple, I mean store the key locally or in your code "hidden" as best you can. No, this isn't ideal or the approach you'd deploy widely - in fact, it's more of a backdoor - but it's a starting point. In the meantime, study the options for key management and storage and determine what will work best for your app and its intended use/environment.

    I'm writing an app for which I'll have to solve this problem, and I haven't figured it out yet. It's seems the mobile environments, like Android, must have a reasonable approach, but I haven't learned them yet. The various Linux desktop environments use a local key/password manager that is locked (and I assume encrypted), requiring the user to enter a single password (the master key?) to unlock and decrypt. Once opened, the manager then provides the necessary passwords/keys to all applications that know how to use it and have permission to do so.

    If you come across some great solutions in your study, let me know.

Similar Threads

  1. I need help to write encrypt and decrypt 4 digit numbers.
    By shin777 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 29th, 2013, 01:07 PM
  2. [SOLVED] Encrypt Decrypt
    By dianac in forum What's Wrong With My Code?
    Replies: 15
    Last Post: April 14th, 2013, 11:01 AM
  3. Encrypt a text message
    By dianac in forum What's Wrong With My Code?
    Replies: 19
    Last Post: April 12th, 2013, 09:32 PM
  4. [SOLVED] Unable to encrypt using AES 256bits
    By fuweng in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 5th, 2011, 07:44 AM
  5. Need Help for encrypt/decrypt.
    By superdhebz in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 17th, 2010, 12:17 PM