Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Saving an encrypted password

Posted on 2001-06-20
4
Medium Priority
?
229 Views
Last Modified: 2010-08-05
I would like to save an encrypted password using the Properties.store method.  The problem is that all encryption algorithms return a byte array and I need to store a string.

Is there a way to use the store method with an encrypted password?
0
Comment
Question by:rossc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
Kobold earned 150 total points
ID: 6211988
Take your byte and transfort them in HEX format like
E50756

Code will look like:

public class Hex {

    private static final char hexDigits[] = {
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'A', 'B', 'C', 'D', 'E', 'F'
    };

    public static String toString(byte abyte0[], int i, int j) {
        char ac[] = new char[j * 2];
        int k = 0;
        for(int l = i; l < i + j; l++) {
            byte byte0 = abyte0[l];
            ac[k++] = hexDigits[byte0 >>> 4 & 0xf];
            ac[k++] = hexDigits[byte0 & 0xf];
        }

        return new String(ac);
    }

    public static String toString(byte abyte0[]) {
        return toString(abyte0, 0, abyte0.length);
    }
};
0
 
LVL 3

Expert Comment

by:Kobold
ID: 6211999
I forgot to send the code for passing from string to byte:

    public static byte[] fromString(String s) {
        int i = s.length();
        byte abyte0[] = new byte[(i + 1) / 2];
        int j = 0;
        int k = 0;
        if(i % 2 == 1)
            abyte0[k++] = (byte)fromDigit(s.charAt(j++));
        while(j < i)
            abyte0[k++] = (byte)(fromDigit(s.charAt(j++)) << 4 | fromDigit(s.charAt(j++)));
        return abyte0;
    }
0
 
LVL 3

Expert Comment

by:Kobold
ID: 6212005
Oups...

    public static int fromDigit(char c) {
        if(c >= '0' && c <= '9')
            return c - 48;
        if(c >= 'A' && c <= 'F')
            return (c - 65) + 10;
        if(c >= 'a' && c <= 'f')
            return (c - 97) + 10;
        else
            throw new IllegalArgumentException("invalid hex digit '" + c + "'");
    }

0
 

Author Comment

by:rossc
ID: 6212582
I used the Acme.Crypto algorithm to encrypt the password.  To write it to disk, I had to create a string using ISO 8859-1 character encoding - new String(cipherText,"ISO-8859-1").

The Properties methods setProperty, getProperty, and store worked fine with the ISO-8859-1 strings.

Kobold,  your answer probably would have worked so I will give you the points.
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question