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.

}<br />

private Coin[] mergeCoinArrays(Coin[] a, Coin[] b)<br />

{<br />

Coin[] c = new Coin[a.length + b.length];<br />

int i = 0;<br />

for(; i < a.length; i++)<br />

{<br />

c[i] = a[i];<br />

}<br />

for(; i < a.length + b.length; i++)<br />

{<br />

c[i] = b[i];<br />

}<br />

return c;<br />

}<br />

private byte[] mergeByteArrays(byte[] a, byte[] b)<br />

{<br />

byte[] c = new byte[a.length + b.length];<br />

int i = 0;<br />

for(; i < a.length; i++)<br />

{<br />

c[i] = a[i];<br />

}<br />

for(; i < a.length + b.length; i++)<br />

{<br />

c[i] = b[i];<br />

}<br />

return c;<br />

}<br />

public boolean isOpen()<br />

{<br />

return isOpen;<br />

}<br />

public void saveToFile() throws Exception<br />

{<br />

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

"Saving Safe to " + Config.safeFilePath + " using password: " +<br />

password<br />

+ " and key-file-path: "<br />

+ keyFilePath);<br />

if(!isOpen())<br />

throw new Exception("The safe is not open. Cannot save to disk");<br />

password);<br />

password);<br />

String error = "";<br />

try<br />

{<br />

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

Debugger.debug(getClass(), 3, "Encrypting the privatekey.");<br />

byte[] passEncryptedKey = Cryptotools.encryptWithPassword(privatekey,<br />

byte[] encryptedKey = Cryptotools.encryptAES(passEncryptedKey, key);<br />

Debugger.debug(getClass(), 3, "Encrypting the safe.");<br />

byte[] passEncryptedSafe = Cryptotools.encryptWithPassword(safe, password);<br />

byte[] encryptedSafe = Cryptotools.encryptAES(passEncryptedSafe, key);<br />

Debugger.debug(getClass(), 3, "Encrypting the pending mails.");<br />

byte[] passEncryptedMails = Cryptotools.encryptWithPassword(pendingMails,<br />

byte[] encryptedMails = Cryptotools.encryptAES(passEncryptedMails, key);<br />

Debugger.debug(getClass(), 3, "Encrypting the coin history.");<br />

byte[] passEncryptedCoinHistory =<br />

Cryptotools.encryptWithPassword(coinHistory, password);<br />

byte[] encryptedCoinHistory =<br />

Cryptotools.encryptAES(passEncryptedCoinHistory, key);<br />

305

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

Saved successfully!

Ooh no, something went wrong!