1 package com.calipso.reportgenerator.common; 2 3 import java.net.InetAddress ; 4 import java.net.UnknownHostException ; 5 6 12 public class LocalKeyEncrypter { 13 14 public static String encrypt(String data) throws Exception { 15 String localKey = getKey(); 16 return encrypt(data, localKey); 17 } 18 19 public static String decrypt(String data) throws Exception { 20 String localKey = getKey(); 21 return decrypt(data, localKey); 22 } 23 24 private static String decrypt(String data, String localKey) throws Exception { 25 Encrypter encrypter = new Encrypter(localKey); 26 return encrypter.decrypt(data); 27 } 28 29 private static String encrypt(String data, String localKey) throws Exception { 30 Encrypter encrypter = new Encrypter(localKey); 31 return encrypter.encrypt(data); 32 } 33 34 private static String getKey() { 35 String key = ""; 36 try { 37 key += InetAddress.getLocalHost().getHostName(); 38 } catch (UnknownHostException e) { 39 e.printStackTrace(); 41 } 42 key += System.getProperty("os.name"); 43 key += System.getProperty("os.arch"); 44 return key; 46 } 47 48 } 49 | Popular Tags |