29.07.2013 Views

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

keyBytes = (byte[]) in.readObject();<br />

safeBytes = (byte[]) in.readObject();<br />

mailBytes = (byte[]) in.readObject();<br />

coinBytes = (byte[]) in.readObject();<br />

stream.close();<br />

in.close();<br />

}<br />

else<br />

{<br />

keyBytes = FileHandler.readBytes(new<br />

File(Config.privateKeyFilePath));<br />

safeBytes = FileHandler.readBytes(new File(Config.safeFilePath));<br />

mailBytes = FileHandler.readBytes(new<br />

File(Config.pendingMailsFilePath));<br />

coinBytes = FileHandler.readBytes(new<br />

File(Config.coinHistoryFilePath));<br />

}<br />

}<br />

catch(FileNotFoundException ex)<br />

{<br />

Debugger.debug(getClass(), 1, "The safefiles could not be found. Creating<br />

new safe file.");<br />

password);<br />

password);<br />

}<br />

//Create a new Safe<br />

Control.generateKeyFile(Config.defaultSafeKeyFilePath);<br />

safe = new Safe();<br />

pendingMails = new Vector();<br />

coinHistory = new CoinHistory();<br />

this.keyFilePath = keyFilePath;<br />

this.password = password;<br />

isOpen = true;<br />

saveToFile();<br />

return;<br />

SecretKey key = (SecretKey) FileHandler.readObject(new File(keyFilePath));<br />

//Restoring Private key<br />

byte[] decrypted = Cryptotools.decryptAES(keyBytes, key);<br />

this.privatekey = (RSAPrivateKey) Cryptotools.decryptWithPassword(decrypted,<br />

//Restoring Safe<br />

decrypted = Cryptotools.decryptAES(safeBytes, key);<br />

safe = (Safe) Cryptotools.decryptWithPassword(decrypted, password);<br />

//Restoring pending mails<br />

decrypted = Cryptotools.decryptAES(mailBytes, key);<br />

pendingMails = (Vector) Cryptotools.decryptWithPassword(decrypted, password);<br />

//Restoring coinHistory<br />

decrypted = Cryptotools.decryptAES(coinBytes, key);<br />

coinHistory = (CoinHistory) Cryptotools.decryptWithPassword(decrypted,<br />

//Save the safeinformation<br />

this.keyFilePath = keyFilePath;<br />

this.password = password;<br />

isOpen = true;<br />

Debugger.debug(getClass(), 1, "Safe loaded succesfully.");<br />

return;<br />

}<br />

catch(FileNotFoundException fnf)<br />

{<br />

error = "The safe could not be opened. The keyfile " + keyFilePath<br />

+ " was not found. Please specify the correct path.";<br />

Debugger.debug(getClass(), 1, error, fnf);<br />

}<br />

catch(Exception ioe)<br />

307

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!