From 823736aecc3dbe8a27e8391ce55bf0fad661d5d9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 6 Jan 2020 19:59:55 +0100 Subject: [PATCH] facepalm --- eu.steffo.cleaver.iml | 1 + examples/loremipsum.txt.c1 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c2 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c3 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c4 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c5 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c6 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c7 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c8 | Bin 1024 -> 0 bytes examples/loremipsum.txt.c9 | Bin 817 -> 0 bytes examples/loremipsum.txt.chp | 1 - src/eu/steffo/cleaver/gui/CleaverFrame.java | 2 +- src/eu/steffo/cleaver/logic/ChopJob.java | 3 +- src/eu/steffo/cleaver/logic/StitchJob.java | 5 +- .../cleaver/logic/crypt/CryptInputStream.java | 104 +++++++++++++++- .../logic/crypt/CryptOutputStream.java | 113 +++++++++++++----- 16 files changed, 190 insertions(+), 39 deletions(-) delete mode 100644 examples/loremipsum.txt.c1 delete mode 100644 examples/loremipsum.txt.c2 delete mode 100644 examples/loremipsum.txt.c3 delete mode 100644 examples/loremipsum.txt.c4 delete mode 100644 examples/loremipsum.txt.c5 delete mode 100644 examples/loremipsum.txt.c6 delete mode 100644 examples/loremipsum.txt.c7 delete mode 100644 examples/loremipsum.txt.c8 delete mode 100644 examples/loremipsum.txt.c9 delete mode 100644 examples/loremipsum.txt.chp diff --git a/eu.steffo.cleaver.iml b/eu.steffo.cleaver.iml index 5770e2e..971f913 100644 --- a/eu.steffo.cleaver.iml +++ b/eu.steffo.cleaver.iml @@ -6,6 +6,7 @@ + diff --git a/examples/loremipsum.txt.c1 b/examples/loremipsum.txt.c1 deleted file mode 100644 index a55d884952c738aeb3a78f9f9823d8d019dc56c8..0000000000000000000000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X&a4WHZE-{u=Eni&&=YQ9^j5Np`hplyb6R8I%6 z&{+S7I0Z4oCkD}L=M!Y)EE3vajSV>wR5I5O3z0{wLjhETb+F;t^AWKv`t z(5`uj6QJR{F@ou}9f9A*Xy&T+)^k4yHF5wfJ-m795CTs=7voN*8_1v)anz(}l0*WUESV){*?dtc_Cj0%< z5#~xs^xK!IwX|#%!vi|&Q{4(pz^sHNH!I0HfVH~|kBgMm;G5&_=-VQGG6oLB(c^x? z>q>WnF$3CgXN^w;`Q;^OzrrrAzp!WHgX5nd7?RgtpcZE0m>zb~9J5xPzWV!`GFJis zh#VbM-KJCz&^;5H?+7Qj*88K}&Ar&VQtA^nX-^yKR71LR)pq8EX10nc&x)+p_8NY# zfH3`jgOU(U0d(qtuF4!4I?Fu8ku-biX#{kbNaqMwD6c)hX>%bPCo$)%qF;)rDB6`F ugb2sz#Qab@9Xb}b`GI=6!~k1qf^g_Dj`Li7dE3Ppc*C!Ck+?vi8`UvX) diff --git a/examples/loremipsum.txt.c3 b/examples/loremipsum.txt.c3 deleted file mode 100644 index 64e357b210eb5bf135d8bdb5009ce9be986a5d14..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmV+b1poWVHg*NmjSjzdJmrG& z`+jbL0RT=>v(Y$br~_SH2tXm9#Hf@gib_fklsR0Y>ChRB5H~Y`+9g3ohv>K+!9U^! zKrE;P4SR7j#giCZKH?}SF#uxm6Y!)W&~i1x_H^>27#v>()$q539FGrCWBb&|00QAd zhZsbc@fWj~Hy&5PMJ;M84uwndR%2{+ciW|-`T|LuzF<=+aE^O0~iwv;Bn}igx zuu)dmS%VXV>h?-jfA3?iJc=<7e(HlR)0!-`i83xUy!k*!VV3v<`I*teF3uETS;Gz~ zILUR0hjZCs>cB=G20rWeORMVt-S;9UDWYKKM)VJ|7g6_srkdbL-_GRQKsF$uZQdhU zhcV3=MTaEctknj%pZv3FPRObq%WzcJd&+&r5D*O38pD1v7XpI4#zos93Q+wN>cugI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f|?i6-u6<&O6hOcsXVjqUKd9GYo~ief0{>+#~P(93;*QS>g2Be_NUQt?t8 zCB$VKlr%B{8UWw0cWvM_rWH#5{~wh9CQC z5jSctFRB4G6PiVQB~(k|L?*Mvjw2srr&=v?#@$G8+Cz%e!fA>eDZI!G@yRD~#~^Ey zdIl97ILc&#I;b21@GaqnUU>Phr0mb928P4*ZuL0B+Jt>=D0V$8*LJGIWQ4D=EU%$& u=XwWlcfre?mMlJyGsMy>A0lkQZW*YsnPWW{I diff --git a/examples/loremipsum.txt.c5 b/examples/loremipsum.txt.c5 deleted file mode 100644 index 1601410db1bdd19c6483b8a2771c52669e93b426..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmV+b1poUtn8`?lcXDEDCZ96LVkfuCsNjWD2qlV4ehrT#bkp-XrpmQI*rS=59Hr$` zx!YxT!T5gKD6}O!5oc!iz5KY8isqYH+51LP;8Z~@JoDwM-ttON)>4yIhQjz7Y@r48 zl3Dqggxf>sJ@)&g<|85%fc4^actu;minWG2?@R98h;v+M#QDs3cN@C%rK3}!k0|-x z?H)u;^36`PiFO6&OVCJ^5lIz$b5t)A%hXZf5bhs~QuLpx9ihbv#WJLeDAjT-Tmeol z>n{MYac>q>IB9=0kRdfu(>_d!nn!T=(oqmUU)_7;+VkTI-MBQ9ImdxZtvoy=&E7&h z18|k_FEuMFC14@eKAU9*J-@G*UV=X1BvyhgCHCe{RMeJwXI6=XC9L+7Bz5QL)F50f zPtG^;P$kNaevfHU79B8fWp!MkTzo*rkAg?45)ESQ7uQ8yUMFogb5RFk6q0mEWpC3pZVQHADJw@X~Ch#BDn6o^svKiVZ^h+EB zt_cr{#t3hiKE_G~!Afju;erZr)HHhueM$gd!o?9*Ku<_ZBQ?5Z7O<8~Q-cS;UW((Q0c(J$fqj94H_wX;R%p?^~a-~BFX8mu%1A-Wf3S)S1ki{oflM6YvD zy@`oQ%MJ)Uk`~^kwT95XOhl&cIcx?|(Ps?=Ej8Fn(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G-ohiy$eQ`ZEJMH#C$Vf|MuiWFn1&TWxTpXFd2D+WAr@$ diff --git a/examples/loremipsum.txt.c7 b/examples/loremipsum.txt.c7 deleted file mode 100644 index 38c3caf9b481e9bb5ac4557f7a6b8989d1abf35c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmV+b1poWS3&PhzL_*gNyp$8P6(ot0fCw7aq8MPljTK_m)edjZhpG-?po}dj&ikGQhz zvrq~8oqAGjPgV!*6-^y{uvcOokMjcn<7|PbzTb-RZW<1e8|oZT<{h5okJYvnT_G71 z&gm%}im}@(BU5fSYgW0YM)u_I(qnBy3Rk!_I-E(Mvq`2eQUZeIrbL~iM6ZMX-Vuar>f zY|Q1e_8z)tU9>#v8^ai5rzwRoBCZCSi7g~BXgQ13>pb1>IQ@^i-6#@X($wEZ2z#Dy z-|Olpi;rp`5?TdfyaGo3G00F-EHNJ}C$*}@Nu3Z`yN+J^aGEq7>@J~F7d4}k(n*3N zs-xKhUq-C}ti0hI33AmVYH*L&6r~%Vb)mf^D4`=#c}0g$OgX@NFstiFEk%y`m!7Z< z`K*Bpx%v?eE5+7-|*|5Hn|Ey%AKGmQPuH_hb%1 z7EqYNrx%HETG#=}n9oWWr09Pnv_H4lB-o5wPlvHe%H|xl%M?b6ytBSdWov!wF_PZO z__y7rucn4D$$aJ0F$30OW$QmM6eBZ~v`g7si(#MlKeA9JNI@B! z!5E|oa13b!InLy-JV1QbpH|0eDFSigG|-3Pi5Vwjk?WJu(9E_)MJ9l_^Eu1jnH>%b z5+uH_C1#@`+D1GB-_2X;-BS-nSWYrhnn)Co&u4j3yKVN?FY zLqArmz!r$tN4o=}A)~P^25OB_0@l-TJ#pzfIBL&TSE$GRWmV0x;6hKq^ z3JbR?hoST16`ZIgKc=z&BMcDSM>F~v(*|gR6}FA}j!=*|j5<9tP|~hBi4_YhoJn%O zRu&%B5?=i7TqXrG5(4a=@-L_4d?@A<_ZrAgbu(26QAW9Iol(J>BtVlwoC2)m8g5HD uF)~T3XbGnm@G8-$wLK|d@-x*$*;3Sokp+leYQu1vc(nDEpH6pNwQQ^n{ diff --git a/examples/loremipsum.txt.c8 b/examples/loremipsum.txt.c8 deleted file mode 100644 index 2b0582bf3c91b2d4ee158818825e6fb07b18c5fc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmV+b1poWoYM>fVfso99Wvlp9x((iZSly{q;(pE6YNRmg0KYQsvyMgU+c)-U7DjPm z2q{A&@a62Dyg{T+5_bV+_#Aba$nn0s$O9^KXi?1`Sw{Tt{Qza}RF}m~MlOaDTh97d zjEs<=7+pb!w}XE6M$-LSx+WCbv#3p6hrTx=p}CkL&01I=L*wH6+u92qSz`>niQ=Jo z>zktj&N|7hSJA$$aPa*j% zoWno%wwScVJBG4no3nv~?^TOk*`x+h{lomA=c&@m^CS2g4r2Z!$38L+H0o>4QP-nS zl*UHP0`MXZ+RxOjYt)#u?A8KQk1G_O4?9^MGHyr^gU=?M@Dj*6C`^#4I z{#<58(jT`}vOF=}m%+3xE0nZ?FD%lL-3Y3g3A$1ThYQ+POw@aM;aJR4t;wi*<=yRQ z1b;crOAmL2WImw#os)fY2x8eJ)wyk+NDjqOc)G8$L4gl$aye>1WmihAh)CBeP(P6a zYHFomWRStWXspF!BFW8Sf+a_FCqu#P`5f!yH>7$<^<9fsg@c1Yh2cyw&5mVdYKjIo za=tt(uDt;f2gmjqih3EN;*r)Em!sdWNJ9V}LIB_oCAxgpI*OsQ5_wt^=OD!I@c04OW;qqnhi%KE zC@wVT*S%>=x15Dp>NUFve>AbV&!?LBh#!?HUnMY{{%#qatXYHM#Kt@*Skj!9e2c1w uu0ppjv?v2b3tIu-*h*x}2lk2xb{C0)<}y39gHk0nbO14<663$bdT_X;ZS^An diff --git a/examples/loremipsum.txt.c9 b/examples/loremipsum.txt.c9 deleted file mode 100644 index 33e43a263e6c28adbf6c0119338b9230459866e7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 817 zcmV-11J3**P$f1$m7vYO#L=&-L|iqNUB8Lb&GZ>5_o=DVIY=w$h6=~aKmY^5;wXEM z04giB3K_ttV$UKG{!|RFJ0DZiV?F^sG}A_8s;56wCX|T$HJvPIy|4X@HjjKqk2ef% z`~pCYNU9~K&hdoDLbVWNBc!|f+zgFrn@R_D`+H=L7zK(x4@d+_L)Rrld%{)2CV!0| zJPG@%9|+l}Ct1?KGIRX`nQsR;P)3?Y+3T(bx>&n1I4<)6WZcC^J+cJ0-RAwG{W(+32co%{0{hcLb@q{Ph8sqAoA2R_5+| z{5e6m@@0fm{xVv0Kvc(vi2+33b;`;jv0)AF?tVr{XB9;8r%c%}j5_$Jp-DxR@1KCgxBay6JyeFuv9F1;=Ve;%ncXoDefQ zzdefGg+;~uc&|p82vp5ndXpy(5o?w|Aj;>U?c&h#HyJC34FCXaLru$zYjEZ{0u^@PK3G|Z>;ekuH?4~K9 zwEkU7H?S_O5O4#S6b0L#V+b^U+(rE)`0`kyGVCXn=TZl7l=8W=(w=4XQPy-JitJa? z7lxM#w>(X3U%z3Od7)D+8}ex6a%6yCzkC#l&Hndd{5ak55XA`#=-KyJgxvSO5G3p_ zsx%8ODHZOEb^qpJ2%(>4NRm>(td$lUsHOzvrvkmI6 z!t(ok_Je>wcGJEX2-4dN_ZA5XK!`q1w*ZWY<_Wuei%!f`zE-r#(6rbbQ zVJeqUR~BV+>)cN|gevg&%$f&t`!S;ArDbePoChKUiNcJ7-q*f|spNRWxFjm@_I_s2 v9cInZ4YXFpf!Qi=H2|dvagLt{gSTB-m+L4Fd+WMX&Df?AHFfloremipsum.txt \ No newline at end of file diff --git a/src/eu/steffo/cleaver/gui/CleaverFrame.java b/src/eu/steffo/cleaver/gui/CleaverFrame.java index 144091b..b15ec90 100644 --- a/src/eu/steffo/cleaver/gui/CleaverFrame.java +++ b/src/eu/steffo/cleaver/gui/CleaverFrame.java @@ -109,7 +109,7 @@ public class CleaverFrame extends JFrame { @Override public void actionPerformed(ActionEvent e) { for(Job job : jobs) { - if(job.getProgress() instanceof NotStartedProgress) + if(job.getState() == Thread.State.NEW) { job.start(); } diff --git a/src/eu/steffo/cleaver/logic/ChopJob.java b/src/eu/steffo/cleaver/logic/ChopJob.java index 444337e..3d5efcd 100644 --- a/src/eu/steffo/cleaver/logic/ChopJob.java +++ b/src/eu/steffo/cleaver/logic/ChopJob.java @@ -98,7 +98,7 @@ public class ChopJob extends Job { outputStream = new SplitFileOutputStream(file.getAbsolutePath(), splitConfig.getPartSize()); } else { - outputStream = new FileOutputStream(String.format("%s.c00", file.getAbsolutePath())); + outputStream = new FileOutputStream(String.format("%s.c0", file.getAbsolutePath())); } if(compressConfig != null) { @@ -160,6 +160,7 @@ public class ChopJob extends Job { this.setProgress(new FinishedProgress()); } catch (Throwable e) { + e.printStackTrace(); this.setProgress(new ErrorProgress(e)); } } diff --git a/src/eu/steffo/cleaver/logic/StitchJob.java b/src/eu/steffo/cleaver/logic/StitchJob.java index eaa3334..c95623a 100644 --- a/src/eu/steffo/cleaver/logic/StitchJob.java +++ b/src/eu/steffo/cleaver/logic/StitchJob.java @@ -193,7 +193,7 @@ public class StitchJob extends Job { inputStream = new SplitFileInputStream(resultFile.getPath(), splitConfig.getPartSize()); } else { - inputStream = new FileInputStream(String.format("%s.c00", resultFile.getAbsolutePath())); + inputStream = new FileInputStream(String.format("%s.c0", resultFile.getAbsolutePath())); } if (compressConfig != null) { @@ -201,7 +201,7 @@ public class StitchJob extends Job { } if (cryptConfig != null) { - inputStream = new CryptInputStream(inputStream); + inputStream = new CryptInputStream(inputStream, cryptConfig.getKey()); } //Pipe everything to the output @@ -220,6 +220,7 @@ public class StitchJob extends Job { this.setProgress(new FinishedProgress()); } catch (Throwable e) { + e.printStackTrace(); this.setProgress(new ErrorProgress(e)); } } diff --git a/src/eu/steffo/cleaver/logic/crypt/CryptInputStream.java b/src/eu/steffo/cleaver/logic/crypt/CryptInputStream.java index 0995979..9049393 100644 --- a/src/eu/steffo/cleaver/logic/crypt/CryptInputStream.java +++ b/src/eu/steffo/cleaver/logic/crypt/CryptInputStream.java @@ -1,14 +1,112 @@ package eu.steffo.cleaver.logic.crypt; import javax.crypto.Cipher; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.SecretKeySpec; import java.io.FilterInputStream; +import java.io.IOException; import java.io.InputStream; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; public class CryptInputStream extends FilterInputStream { + private Cipher cipher; - public CryptInputStream(InputStream in) { - super(in); + /** + * @return The algorithm used for the encryption. + */ + public String getAlgorithm() { + return "AES"; } - //TODO: This doesn't do anything... yet. + /** + * @return The mode of operation used for the encryption. + */ + public String getModeOfOperation() { + return "CFB8"; + } + + /** + * @return The padding used for the encryption. + */ + public String getPadding() { + return "PKCS5Padding"; + } + + /** + * @return The secret key algorithm used in the generation of the final key. + */ + public String getKeyAlgorithm() { + return "PBKDF2WithHmacSHA1"; + } + + /** + * @return The full transformation string as required by {@link Cipher#getInstance(String)}. + */ + public String getTransformationString() { + return String.format("%s/%s/%s", getAlgorithm(), getModeOfOperation(), getPadding()); + } + + + public CryptInputStream(InputStream in, String key) throws InvalidKeyException { + super(in); + + //Setup the cipher object + try { + cipher = Cipher.getInstance(getTransformationString()); + } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { + //Should never happen, as it's predefined + e.printStackTrace(); + return; + } + + //Create the salt + byte[] salt = new byte[8]; + SecureRandom secureRandom = new SecureRandom(); + secureRandom.nextBytes(salt); + + //Create the KeySpec + //Using the recommended 65536 as iteration count + KeySpec spec = new PBEKeySpec(key.toCharArray(), salt, 65536, 256); + + SecretKeyFactory factory; + try { + factory = SecretKeyFactory.getInstance(getKeyAlgorithm()); + } catch (NoSuchAlgorithmException e) { + //Should never happen, as it's predefined + e.printStackTrace(); + return; + } + + //Create the pbkdf secret key + SecretKey pbkdf; + try { + pbkdf = factory.generateSecret(spec); + } catch (InvalidKeySpecException e) { + //Should never happen, as it's predefined + e.printStackTrace(); + return; + } + + //"Convert" the secret key to a AES secret key + SecretKey aes = new SecretKeySpec(pbkdf.getEncoded(), getAlgorithm()); + + //Init the cipher instance + cipher.init(Cipher.DECRYPT_MODE, aes); + } + + @Override + public int read() throws IOException { + int encryptedInt = super.read(); + byte[] encryptedByte = new byte[1]; + encryptedByte[0] = (byte)encryptedInt; + byte[] decryptedByte = cipher.update(encryptedByte); + return decryptedByte[0]; + } } diff --git a/src/eu/steffo/cleaver/logic/crypt/CryptOutputStream.java b/src/eu/steffo/cleaver/logic/crypt/CryptOutputStream.java index a2913e1..ae7eec3 100644 --- a/src/eu/steffo/cleaver/logic/crypt/CryptOutputStream.java +++ b/src/eu/steffo/cleaver/logic/crypt/CryptOutputStream.java @@ -4,68 +4,119 @@ import eu.steffo.cleaver.errors.ProgrammingError; import javax.crypto.Cipher; import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.KeySpec; public class CryptOutputStream extends FilterOutputStream { private Cipher cipher; - private final String algorithm; - private final String modeOfOperation; - private final String padding; - + /** + * @return The algorithm used for the encryption. + */ public String getAlgorithm() { - return algorithm; + return "AES"; } + /** + * @return The mode of operation used for the encryption. + */ public String getModeOfOperation() { - return modeOfOperation; + return "CFB8"; } + /** + * @return The padding used for the encryption. + */ public String getPadding() { - return padding; + return "PKCS5Padding"; } + /** + * @return The secret key algorithm used in the generation of the final key. + */ + public String getKeyAlgorithm() { + return "PBKDF2WithHmacSHA1"; + } + + /** + * @return The full transformation string as required by {@link Cipher#getInstance(String)}. + */ public String getTransformationString() { - return String.format("%s/%s/%s", algorithm, modeOfOperation, padding); + return String.format("%s/%s/%s", getAlgorithm(), getModeOfOperation(), getPadding()); } - public CryptOutputStream(OutputStream out, String key, String algorithm, String modeOfOperation, String padding) throws ProgrammingError { + /** + * Create a new CryptOutputStream with default {@link Cipher} parameters. + * (AES algorithm in operation mode CFB8 with PKCS5 padding) + * + * Does not use this as {@literal try} and {@literal catch} are not supported. + * + * @param out The {@link OutputStream} to connect this {@link FilterOutputStream} to. + * @param key The desired encryption key. + */ + public CryptOutputStream(OutputStream out, String key) throws InvalidKeyException { super(out); - this.algorithm = algorithm; - this.modeOfOperation = modeOfOperation; - this.padding = padding; - //Setup the cipher object try { cipher = Cipher.getInstance(getTransformationString()); - } catch (NoSuchAlgorithmException e) { - // This should never happen. - throw new ProgrammingError("Invalid algor specified in the CryptOutputStream."); - } catch (NoSuchPaddingException e) { - // This should never happen. - throw new ProgrammingError("Invalid padding specified in the CryptOutputStream."); + } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { + //Should never happen, as it's predefined + e.printStackTrace(); + return; } - try { - cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes(), this.algorithm)); - } catch (InvalidKeyException e) { - // This should never happen. - throw new ProgrammingError("Invalid key specified in the CryptOutputStream."); - } - } - public CryptOutputStream(OutputStream out, String key) throws ProgrammingError { - this(out, key, "AES", "CBC", "PKCS5Padding"); + //Create the salt + byte[] salt = new byte[8]; + SecureRandom secureRandom = new SecureRandom(); + secureRandom.nextBytes(salt); + + //Create the KeySpec + //Using the recommended 65536 as iteration count + KeySpec spec = new PBEKeySpec(key.toCharArray(), salt, 65536, 256); + + SecretKeyFactory factory; + try { + factory = SecretKeyFactory.getInstance(getKeyAlgorithm()); + } catch (NoSuchAlgorithmException e) { + //Should never happen, as it's predefined + e.printStackTrace(); + return; + } + + //Create the pbkdf secret key + SecretKey pbkdf; + try { + pbkdf = factory.generateSecret(spec); + } catch (InvalidKeySpecException e) { + //Should never happen, as it's predefined + e.printStackTrace(); + return; + } + + //"Convert" the secret key to a AES secret key + SecretKey aes = new SecretKeySpec(pbkdf.getEncoded(), getAlgorithm()); + + //Init the cipher instance + cipher.init(Cipher.ENCRYPT_MODE, aes); } @Override - public void write(int b) throws IOException { - //TODO - super.write(b); + public void write(int decryptedInt) throws IOException { + byte[] decryptedByte = new byte[1]; + decryptedByte[0] = (byte)decryptedInt; + byte[] encryptedByte = cipher.update(decryptedByte); + int encryptedInt = encryptedByte[0]; + super.write(encryptedInt); } }