KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > util > Scrambler


1 package hudson.util;
2
3 import ch.ethz.ssh2.crypto.Base64;
4
5 import java.io.UnsupportedEncodingException JavaDoc;
6 import java.io.IOException JavaDoc;
7
8 /**
9  * Used when storing passwords in configuration files.
10  *
11  * <p>
12  * This doesn't make passwords secure, but it prevents unwanted
13  * exposure to passwords, such as when one is grepping the file system
14  * or looking at config files for trouble-shooting.
15  *
16  * @author Kohsuke Kawaguchi
17  */

18 public class Scrambler {
19     public static String JavaDoc scramble(String JavaDoc secret) {
20         try {
21             return new String JavaDoc(Base64.encode(secret.getBytes("UTF-8")));
22         } catch (UnsupportedEncodingException JavaDoc e) {
23             throw new Error JavaDoc(e); // impossible
24
}
25     }
26
27     public static String JavaDoc descramble(String JavaDoc scrambled) {
28         try {
29             return new String JavaDoc(Base64.decode(scrambled.toCharArray()),"UTF-8");
30         } catch (IOException JavaDoc e) {
31             return ""; // corrupted data.
32
}
33     }
34 }
35
Popular Tags