1 import java.io.*; 2 import java.security.SecureRandom ; 3 import java.util.zip.*; 4 import whisper.*; 5 6 7 public final class AccountSettings{ 8 9 public String JabberUserName; 10 public String JabberServer; 11 public String JabberPassword; 12 public String JabberResource; 13 public boolean JabberRememberPassword; 14 public boolean JabberSSL; 15 16 public final static String FILENAME="settings.dat"; 17 18 public AccountSettings(){ 19 } 21 22 public void Save() throws IOException{ 23 File file=new File(WhisperIM.userDir,FILENAME); 24 FileOutputStream fos=new FileOutputStream(file,false); 25 26 Twofish tf=new Twofish(); 27 tf.initEncrypt(WhisperIM.MainWindow.keycachekey ,WhisperIM.SR); 28 fos.write(tf.getIV(),0,tf.getBlockSize()); 29 30 EncryptOutputStream eos=new EncryptOutputStream(fos,tf); 31 32 DeflaterOutputStream dos=new DeflaterOutputStream(eos); 33 34 35 36 PrintStream ps=new PrintStream(dos, true); 37 38 ps.println(JabberUserName); 39 ps.println(JabberServer); 40 if(JabberRememberPassword){ 41 ps.println(JabberPassword); 42 } 43 else{ 44 ps.println(""); 45 } 46 if(JabberSSL){ 47 ps.println("true"); 48 } 49 else{ 50 ps.println("false"); 51 } 52 ps.println(JabberResource); 53 54 55 ps.flush(); 56 ps.close(); 57 fos.flush(); 58 fos.close(); 59 } 60 61 public void Load() throws IOException, CryptoException{ 62 File file=new File(WhisperIM.userDir,FILENAME); 63 FileInputStream fis=new FileInputStream(file); 64 65 DecryptInputStream dis=new DecryptInputStream(fis,WhisperIM.MainWindow.keycachekey); 66 67 InflaterInputStream iis=new InflaterInputStream(dis); 68 69 InputStreamReader isr=new InputStreamReader(iis); 70 BufferedReader br=new BufferedReader(isr); 71 72 JabberUserName=br.readLine(); 73 if(JabberUserName==null){ 74 throw new IOException("File truncated"); 75 } 76 77 JabberServer=br.readLine(); 78 if(JabberServer==null){ 79 throw new IOException("File truncated"); 80 } 81 82 JabberPassword=br.readLine(); 83 if(JabberPassword==null){ 84 throw new IOException("File truncated"); 85 } 86 if (JabberPassword.equals("")){ 87 JabberRememberPassword=false; 88 } 89 else{ 90 JabberRememberPassword=true; 91 } 92 93 String tmp=br.readLine(); 94 if(tmp==null){ 95 throw new IOException("File truncated"); 96 } 97 if(tmp.equals("false")){ 98 JabberSSL=false; 99 } 100 else{ 101 JabberSSL=true; 102 } 103 104 JabberResource=br.readLine(); 105 if(JabberResource==null){ 106 throw new IOException("File truncated"); 107 } 108 109 br.close(); 110 isr.close(); 111 iis.close(); 112 dis.close(); 113 fis.close(); 114 } 115 116 } | Popular Tags |