<?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 Piyush Wani on Medium]]></title>
        <description><![CDATA[Stories by Piyush Wani on Medium]]></description>
        <link>https://medium.com/@piyushwani?source=rss-db730973f69e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*k6aNjYDH0txwi-Uf.</url>
            <title>Stories by Piyush Wani on Medium</title>
            <link>https://medium.com/@piyushwani?source=rss-db730973f69e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:15:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piyushwani/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[Client Side Password Encryption in Rails]]></title>
            <link>https://medium.com/@piyushwani/client-side-password-encryption-in-rails-2dddd0349c6c?source=rss-db730973f69e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dddd0349c6c</guid>
            <category><![CDATA[devise]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[client-side-encryption]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Piyush Wani]]></dc:creator>
            <pubDate>Fri, 06 Sep 2019 06:20:14 GMT</pubDate>
            <atom:updated>2019-09-06T06:20:14.799Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/plataformatec/devise">Devise</a> Gem is a set of flexible solutions for sophisticated Authentication system in Rails and its pretty easy to use. Devise provides us Server side password encryption, but seamless authentication with client side encryption is yet to be implemented in Devise. It can make our platform bit vulnerable, as login passwords and sensitive information passed through the form is still visible through the console.</p><p>Now we have different encryption algorithms that we can use but I think Public key cryptography is the best choice in this scenario it involves client side encryption. I have implemented this mechanism using <em>RSA</em> algorithm.</p><p>This mechanism mainly requires to set of keys (<em>public key and private key</em>). Public key as the name suggests, will be available for everyone, so it will be there on the client side(View part) for encryption. Private key will be present on the server side for decryption.</p><p>So here’s how we can implement Client side encryption in Rails (3 and On wards)</p><ul><li>Add <a href="https://github.com/travist/jsencrypt/blob/master/bin/jsencrypt.js"><strong>JsEncrypt</strong></a> library in your rails project (vendor/assets/javascripts folder)</li><li>You require set of keys to be generated in the beginning every time when you want to do encryption /decryption for particular API cycle, for that create a library file which generates <em>RSA</em> key pair.</li><li><em>RSA</em> Encryptor mentioned below is a simple wrapper on core ruby <strong>OpenSSL::PKey::RSA</strong> module.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fbdfe9a35a20e241f11e5116a5dc1a6/href">https://medium.com/media/3fbdfe9a35a20e241f11e5116a5dc1a6/href</a></iframe><p>We will take Login API Cycle in this example</p><ul><li>While rendering the login form, we will create public - private key pair using <em>RSA</em> Encryptor.</li><li>Helper is used here as we are passing an instance variable (@public_key) to UI template(erb). Session Helper requires <em>RSA</em> Encryptor to pass Public key to Client side and store Private key in the Server’s Session.</li><li>Generate Devise Controllers and Views if not generated. We will need a Sessions Controller to make changes in Devise’s default session handling mechanism.</li></ul><pre>rails generate devise:controllers [scope]</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a08e9324ce5b2726aef15f7674af002/href">https://medium.com/media/9a08e9324ce5b2726aef15f7674af002/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8e9c73714d138b4ef2cfab3526decaa/href">https://medium.com/media/a8e9c73714d138b4ef2cfab3526decaa/href</a></iframe><ul><li>Pass the public_key to client side(views/sessions/new.html.erb)</li></ul><pre>&lt;div class=&quot;input-container&quot;&gt;<br>   &lt;%= f.password_field :password, placeholder: &quot;Password&quot;, tabindex: &quot;2&quot;, required: &quot;required&quot;, data: { encrypt: true } %&gt;&lt;/div&gt;<br>&lt;div class=&quot;hidden&quot; id=&quot;public_key&quot; data-value= &quot;&lt;%= sanitize <a href="http://twitter.com/public_key">@public_key</a> %&gt;&quot;&gt;&lt;/div&gt;</pre><ul><li>Encrypt the password using public key upon form submission.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d4350050b121cbffb05631e5143075f/href">https://medium.com/media/2d4350050b121cbffb05631e5143075f/href</a></iframe><p><a href="https://gist.github.com/peiyush13/dce558769203d98d27699d9c93d70f4d">Reference</a> for all scripts.</p><p>This is how you can achieve Client side Encryption in Rails.</p><p>I hope, This blog is helpful.</p><p>Happy Coding !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dddd0349c6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>