<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 5, 2014 at 2:49 PM, Matthias Wessendorf <span dir="ltr">&lt;<a href="mailto:matzew@apache.org" target="_blank">matzew@apache.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hello Bruno,<br><div class="gmail_extra"><br>

<br><div class="gmail_quote"><div class="im">On Wed, Feb 5, 2014 at 5:05 PM, Bruno Oliveira <span dir="ltr">&lt;<a href="mailto:bruno@abstractj.org" target="_blank">bruno@abstractj.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">You shouldn&rsquo;t store your private key, please make use of the suggested code and let me know.<br>


</blockquote><div><br></div>
<div><br></div></div><div>OK, not storing the &#39;private key&#39;, but instead I am only storing the IV, salt and&nbsp;ciphertext, right ?&nbsp;</div></div></div></div></blockquote><div><br></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Right. In this case you don&#39;t need store Private Key</span><br>

</div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">

<div class="gmail_quote"><div>The following code is basically the (relevant) code behind the web-form when someone creates the logical construct of an iOS variant:</div>
<div><br></div><div><a href="https://github.com/matzew/psswd-salting/blob/master/src/test/java/net/wessendorf/salt/SecretKeyTest.java#L44-L62" target="_blank">https://github.com/matzew/psswd-salting/blob/master/src/test/java/net/wessendorf/salt/SecretKeyTest.java#L44-L62</a><br>


</div><div><br></div><div>In real I get all the information for the variant (e.g. its name, its description, its certificate file and the passphrase for the certificate), but the above has been limited to the passphrase, as everything else is not so important here :-)</div>


<div><br></div><div>So after that I have basically the following pieces in the database:</div><div>* IV</div><div>* salt</div><div>* ciphertex</div><div><br></div><div>instead of the plaintext passphrase for the iOS certs. &nbsp;</div>

</div></div></div></blockquote><div><br></div><div><b>NEVER</b> store password/passphrase</div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">








<div>But, now, somewhere later in in the program, I need to do the decryption to get the actual passphrase for the stored Apple-certificate.<br></div><div>However, I don&#39;t see how to create the CryptoBox here, as I should not stash the private/secret key, nor do I have access to the previous CryptoBox object</div>


<div><br></div><div><a href="https://github.com/matzew/psswd-salting/blob/master/src/test/java/net/wessendorf/salt/SecretKeyTest.java#L64-L85" target="_blank">https://github.com/matzew/psswd-salting/blob/master/src/test/java/net/wessendorf/salt/SecretKeyTest.java#L64-L85</a><br>


</div><div><br></div><div><br></div><div>Looks like I am missing something here</div></div></div></div></blockquote><div><br></div><div>If you have Salt and password you can create a PrivateKey &quot;on the fly&quot;</div>

<div><pre style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div class="" id="LC142" style="padding-left:10px"><span class="" style><br>

</span></div><div class="" id="LC142" style="padding-left:10px"><span class="" style>Pbkdf2</span> <span class="" style>pbkdf2</span> <span class="" style="font-weight:bold">=</span> <span class="" style>AeroGearCrypto</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">pbkdf2</span><span class="" style="font-weight:bold">();</span></div>

<div class="" id="LC143" style="padding-left:10px"><span class="" style="color:rgb(68,85,136);font-weight:bold">byte</span><span class="" style="font-weight:bold">[]</span> <span class="" style>rawPassword</span> <span class="" style="font-weight:bold">=</span> <span class="" style>pbkdf2</span><span class="" style="font-weight:bold">.</span><span class="" style="color:teal">encrypt</span><span class="" style="font-weight:bold">(</span><span class="" style>passphrase</span><span class="" style="font-weight:bold">,</span> <span class="" style>salt</span><span class="" style="font-weight:bold">);</span></div>

<div class="" id="LC144" style="padding-left:10px"><span class="" style>PrivateKey</span> <span class="" style>privateKey</span> <span class="" style="font-weight:bold">=</span> <span class="" style="font-weight:bold">new</span> <span class="" style>PrivateKey</span><span class="" style="font-weight:bold">(</span><span class="" style>rawPassword</span><span class="" style="font-weight:bold">);</span></div>

</pre></div><div>&nbsp;</div><div>And for create CriptoBox you only need a PrivateKey</div><div><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"><br>

</span></div><div><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"><span style="font-size:12px;font-weight:normal">  CryptoBox</span><span style="color:rgb(0,128,128);font-weight:normal"> </span></span><span class="" style="color:teal;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;text-align:start;white-space:pre">cryptoBox</span><span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"> </span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">=</span><span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"> </span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">new</span><span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"> </span><span class="" style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre;background-color:rgb(255,255,255)">CryptoBox</span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">(</span><span class="" style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre;background-color:rgb(255,255,255)">privateKey</span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">);</span><br>

</div><div><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"><br></span></div><div>Now you a able to decrypt using stored IV :)</div>

<div><br></div><div><span class="" style="color:rgb(68,85,136);font-weight:bold;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">  byte</span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">[]</span><span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"> </span><span class="" style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre;background-color:rgb(255,255,255)">decryptedData</span><span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"> </span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">=</span><span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"> </span><span class="" style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre;background-color:rgb(255,255,255)">cryptoBox</span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">.</span><span class="" style="color:teal;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;text-align:start;white-space:pre">decrypt</span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">(</span><span class="" style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre;background-color:rgb(255,255,255)">IV</span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">,</span><span style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre"> </span><span class="" style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre;background-color:rgb(255,255,255)">data</span><span class="" style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:18px;white-space:pre">);</span></div>

<div>







<p class="">That was exactly what we did in Ecrypted Store</p><p class=""><a href="https://github.com/danielpassos/aerogear-android/blob/master/src/org/jboss/aerogear/android/impl/datamanager/EncryptedSQLStore.java#L115-L150">https://github.com/danielpassos/aerogear-android/blob/master/src/org/jboss/aerogear/android/impl/datamanager/EncryptedSQLStore.java#L115-L150</a></p>

<p class=""><br></p></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">

<div class="gmail_quote"><span class=""><font color="#888888"><div>-Matthias</div></font></span></div></div></div></blockquote></div></div></div>