<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yaniv Bouhadana on Medium]]></title>
        <description><![CDATA[Stories by Yaniv Bouhadana on Medium]]></description>
        <link>https://medium.com/@bouhady?source=rss-24e80701458c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8JApvSd4nx2DRyqmydF_gA.jpeg</url>
            <title>Stories by Yaniv Bouhadana on Medium</title>
            <link>https://medium.com/@bouhady?source=rss-24e80701458c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:07:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bouhady/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Kotlin with Dagger 1]]></title>
            <link>https://medium.com/@bouhady/using-kotlin-with-dagger-1-6073a0d5a007?source=rss-24e80701458c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6073a0d5a007</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dagger]]></category>
            <dc:creator><![CDATA[Yaniv Bouhadana]]></dc:creator>
            <pubDate>Wed, 26 Jul 2017 19:00:05 GMT</pubDate>
            <atom:updated>2017-07-26T19:16:08.450Z</atom:updated>
            <content:encoded><![CDATA[<p>I Admit that working with Dagger1 is not the best practice since Dagger2 came out. But still there is huge projects that still using it in a wide scope so it is to complicated to migrate into Dagger2.</p><p>After a few days of struggling with Dagger base junit test using the new shiny language “Kotlin” I came to few insights:</p><h3>Problem №1 : Fields Injection</h3><blockquote>Error : “Dagger does not support injection into private fields”</blockquote><p>Dagger use late injection of fields. from the other hand Kotlin compiler try to fix you own code and convert every public member into private member if it doesn’t recognize the external use of this field. this is a very big problem since Dagger1 is not supporting “private fields injection.</p><p>The solution : add “lateinit” tag before the member declaration.</p><h3><strong>Problem №2 : fields vs. getters</strong></h3><p>Kotlin tend to recognize fields as “getter” of this fields. so is it safer to annotate the fields as “@field:Inject” instead of just simple “@Inject”</p><p>for instance :</p><pre>@field:Inject<br>lateinit var ServiceManagerSuperDuper servicemanager</pre><h3><strong>Problem №3 : Any.class != Object.class</strong></h3><blockquote>Error : Error:Modules must not extend from other classes:</blockquote><p>Dagger use type comparison for modules as part of is reflection tasks. the compilation of Kotlin use “Any” type instead of some “Object” instances. the result is compilation failure for modules classes (the providers).</p><p>I found a few blogs and forums posts which claim that this problem was solved in java 8 compilers such as Jake. since google kill Jake (R.I.P) and the new Java 8 compiler still in beta version we must give up for now Kotlin for the modules itself and write it in Java.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6073a0d5a007" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self Sign Certificate Creation Using Spongy Castle for Android App]]></title>
            <link>https://medium.com/@bouhady/self-sign-certificate-creation-using-spongy-castle-for-android-app-61f1545dd63?source=rss-24e80701458c------2</link>
            <guid isPermaLink="false">https://medium.com/p/61f1545dd63</guid>
            <category><![CDATA[spongy-castle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Yaniv Bouhadana]]></dc:creator>
            <pubDate>Sun, 14 Aug 2016 13:31:04 GMT</pubDate>
            <atom:updated>2016-08-15T08:16:53.702Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m not going to get into the reasons why you should create a self sign certificate programmatically inside your android app. Security experts always tend to find reasons why not to do things like you used to do and explain to you why “their” way is the only acceptable way to do so.</p><p>The only purpose of this article is to summarize my own path to achieve a self sign certificate for a certain system that needs this specific kind of certificate.<br>Before start coding, please make sure you include the Spongy Castle libraries inside your project. You can find them at : <a href="https://rtyley.github.io/spongycastle/">https://rtyley.github.io/spongycastle/</a> . You can do this in various ways, whether you include it dynamically using the grade file or download the jars and include them physically inside your project. Make sure you include all 4 files (core, prov, pkix , pg).<br>After including these libraries inside you project you can start creating your certificate.</p><p>There are 3 main steps to creating the certificate:</p><ol><li>Generating the RSA Key Pair (Public-Private).</li><li>Configuring and Generating the certificate itself.</li><li>Self Signing the certificate.</li></ol><p>Please make sure you advise your security expert before coding these parts — the core of the security mechanism depends on this code.<br>Here are some parameters you should decide before coding: (These are the values I used in this tutorial)</p><ol><li>Algorithm (RSA)</li><li>Bit length (1024)</li><li>Issuer Name (same as subject field)</li><li>Subject field (includes O-tag, OU-tag, L-tag)</li><li>Additional certificate fields</li></ol><p>So let’s’ begin:</p><h4>Generating the RSA Key Pair (Public-Private)</h4><p>The generation of a KeyPair is basically already included in the Android SDK as part of the java libraries/packages (<strong>java.security.KeyPair </strong>and <strong>java.security.KeyPairGenerator</strong>) so if you just need to create KeyPairs you don’t needs to include the Spongy Castle libraries at all.<br>All you need to create a 1024 bit’s RSA KeyPair are these three lines:</p><pre>KeyPairGenerator kpg = KeyPairGenerator.<em>getInstance</em>(&quot;RSA&quot;);<br>kpg.initialize(1024);<br>KeyPair keyPair = kpg.genKeyPair();</pre><p>note that the <em>getInstance() </em>method can throw “NoSuchAlgorithmException” so basically your code should looks like this:</p><pre>KeyPairGenerator kpg = null;<br>try {<br>    kpg = KeyPairGenerator.<em>getInstance</em>(&quot;RSA&quot;);<br>} catch (NoSuchAlgorithmException e) {<br>    e.printStackTrace();<br>}<br>kpg.initialize(1024);<br>KeyPair keyPair = kpg.genKeyPair();</pre><h4>Configure and Generate the certificate itself.</h4><p>Now we needs to create the certification itself.<br>the certification must contain a few parts:</p><ol><li>Issuer name .</li><li>Serial Random number.</li><li>Subject</li><li>From and To Dates</li><li>Public Key Info</li></ol><p>The subject can contain tags from various of known attributes, which are called “RDN” (<a href="https://en.wikipedia.org/wiki/Relative_Distinguished_Name">Relative Distinguished Name</a>) and can be added separately one by one.</p><p>The serial number is a BigInteger value generated by random method.</p><p>The dates of the validity can be set according any policy you choose.</p><p>The Public Key Info is a very important issue : you <strong>must </strong>use the same public key you generated in the previous section using the SubjectPublicKeyInfo.getInstance method. Any manual creation on “new SubjectPublicKeyInfo” will led to a corrupted public key in the certificate.</p><p>Finally after you collect all the components the builder main method can be called and create our certificate.</p><p>This is just an example for a certification — but you can customize it as you need/want:</p><pre>Date startDate = new Date(System.<em>currentTimeMillis</em>() - 24 * 60 * 60 * 1000);<br>Date endDate = new Date(System.<em>currentTimeMillis</em>() + VALIDITY_IN_DAYS * 24 * 60 * 60 * 1000);<br><br>X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.<em>INSTANCE</em>);<br>nameBuilder.addRDN(BCStyle.<em>O</em>,oTAG);<br>nameBuilder.addRDN(BCStyle.<em>OU</em>,ouTAG);<br>nameBuilder.addRDN(BCStyle.<em>L</em>,lTAG);<br><br>X500Name x500Name = nameBuilder.build();<br>Random random = new Random();<br><br>SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfo.<em>getInstance</em>(keyPair.getPublic().getEncoded());<br>X509v1CertificateBuilder v1CertGen = new X509v1CertificateBuilder(x500Name<br>        , BigInteger.<em>valueOf</em>(random.nextLong())<br>        ,startDate<br>        ,endDate<br>        ,x500Name<br>        ,subjectPublicKeyInfo);</pre><h4>Self Sign the certificate</h4><p>Finally we have our certification . Now since we just need it to be self sign and not sign by CA all we need it to use these few lines of code and out certificate is done:</p><pre>// Prepare Signature:<br>ContentSigner sigGen = null;<br>try {<br>    Security.<em>addProvider</em>(new BouncyCastleProvider());<br>    sigGen = new JcaContentSignerBuilder(&quot;SHA256WithRSAEncryption&quot;).setProvider(&quot;SC&quot;).build(keyPair.getPrivate());<br>} catch (OperatorCreationException e) {<br>    e.printStackTrace();<br>}<br>// Self sign :<br>X509CertificateHolder x509CertificateHolder = v1CertGen.build(sigGen);</pre><p>The certificate is held by the x509CertificateHolder and can be exported by .getEncoded() method.</p><p>Good Luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61f1545dd63" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>