KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > common > LocalKeyEncrypter


1 package com.calipso.reportgenerator.common;
2
3 import java.net.InetAddress JavaDoc;
4 import java.net.UnknownHostException JavaDoc;
5
6 /**
7  *
8  * User: jbassino
9  * Date: 31-ago-2005
10  * Time: 10:34:42
11   */

12 public class LocalKeyEncrypter {
13
14     public static String JavaDoc encrypt(String JavaDoc data) throws Exception JavaDoc{
15         String JavaDoc localKey = getKey();
16         return encrypt(data, localKey);
17     }
18
19     public static String JavaDoc decrypt(String JavaDoc data) throws Exception JavaDoc{
20         String JavaDoc localKey = getKey();
21         return decrypt(data, localKey);
22     }
23
24     private static String JavaDoc decrypt(String JavaDoc data, String JavaDoc localKey) throws Exception JavaDoc{
25         Encrypter encrypter = new Encrypter(localKey);
26         return encrypter.decrypt(data);
27     }
28
29     private static String JavaDoc encrypt(String JavaDoc data, String JavaDoc localKey) throws Exception JavaDoc{
30         Encrypter encrypter = new Encrypter(localKey);
31         return encrypter.encrypt(data);
32     }
33
34     private static String JavaDoc getKey() {
35         String JavaDoc key = "";
36         try {
37             key += InetAddress.getLocalHost().getHostName();
38         } catch (UnknownHostException JavaDoc e) {
39             //En el caso que no resuelva el nombre de host, no lo sumará a la clave
40
e.printStackTrace();
41         }
42         key += System.getProperty("os.name");
43         key += System.getProperty("os.arch");
44         //System.
45
return key;
46     }
47
48 }
49
Popular Tags