<?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 iyiola osuagwu on Medium]]></title>
        <description><![CDATA[Stories by iyiola osuagwu on Medium]]></description>
        <link>https://medium.com/@iyiolaosuagwu?source=rss-a5d9a8c339cf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vDd3p6Mud_Ri6G3KboZ9gg.jpeg</url>
            <title>Stories by iyiola osuagwu on Medium</title>
            <link>https://medium.com/@iyiolaosuagwu?source=rss-a5d9a8c339cf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:37:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iyiolaosuagwu/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[Keeping Your React Native App Secure: SSL Pinning and Data Encryption Made Simple]]></title>
            <link>https://medium.com/@iyiolaosuagwu/keeping-your-react-native-app-secure-ssl-pinning-and-data-encryption-made-simple-4205e0ad67ee?source=rss-a5d9a8c339cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/4205e0ad67ee</guid>
            <dc:creator><![CDATA[iyiola osuagwu]]></dc:creator>
            <pubDate>Tue, 21 Oct 2025 23:48:51 GMT</pubDate>
            <atom:updated>2025-10-22T01:49:30.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7zk_xTRtRKoVIqAYRr3mXQ.png" /></figure><p>Let’s be honest — security isn’t the most exciting part of mobile app development. But when you’re handling sensitive data — like login tokens, personal info, or payment details — it’s <em>the</em> part that can make or break your users’ trust.</p><p>In this post, we’ll talk about two of the biggest security layers you can (and should) add to your React Native app: <strong>SSL Pinning</strong> and <strong>Data Encryption</strong>. We’ll keep things practical, with real code examples you can drop right into your project.</p><h3>Why You Should Care About These</h3><p>Even though HTTPS encrypts traffic, it still relies on the system’s trusted certificate authorities (CAs). That means if someone installs a fake root CA on a device or sits in the middle of a public Wi-Fi connection, your app could still talk to a fake server.</p><p>On top of that, data you store locally (like tokens in AsyncStorage) isn’t encrypted by default — so if someone gets access to the device filesystem, they could easily read it.</p><p><strong>That’s where SSL pinning and data encryption come in.</strong></p><ul><li><strong>SSL Pinning</strong> makes sure your app only trusts your real server’s certificate or public key — not any random one claiming to be it.</li><li><strong>Data Encryption</strong> keeps local and transmitted data safe, even if it falls into the wrong hands.</li></ul><p>Let’s break both down.</p><h3>1. SSL Pinning in React Native</h3><h3>What Is It?</h3><p>SSL Pinning (also called certificate or public key pinning) means your app has a copy of your server’s certificate or public key “pinned” inside it. When your app connects to the server, it checks if the certificate matches what it expects. If it doesn’t — boom, connection rejected. No sneaky middlemen allowed.</p><h3>Installing a Pinning Library</h3><p>One of the most popular libraries for React Native is <a href="https://www.npmjs.com/package/react-native-ssl-public-key-pinning?utm_source=chatgpt.com">react-native-ssl-public-key-pinning</a>.<br> It’s simple, supports both iOS and Android, and integrates nicely with fetch.</p><p>Install it with:</p><pre>yarn add react-native-ssl-public-key-pinning<br>cd ios &amp;&amp; pod install &amp;&amp; cd ..</pre><h3>Setting It Up</h3><p>Here’s how to initialize SSL pinning early in your app:</p><pre>import {<br>  initializeSslPinning,<br>  addSslPinningErrorListener,<br>  isSslPinningAvailable,<br>} from &#39;react-native-ssl-public-key-pinning&#39;;<br><br>async function setupSslPinning() {<br>  if (!isSslPinningAvailable()) {<br>    console.warn(&#39;SSL pinning not available — likely running in Expo Go&#39;);<br>    return;<br>  }<br><br>  await initializeSslPinning({<br>    &#39;api.myserver.com&#39;: {<br>      includeSubdomains: true,<br>      publicKeyHashes: [<br>        &#39;CLOmM1/OXvSPjw5UOYbAf9GKOxImEp9hhku9W90fHMk=&#39;,<br>        &#39;hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc=&#39;, // backup<br>      ],<br>    },<br>  });<br><br>  addSslPinningErrorListener((error) =&gt; {<br>    console.error(&#39;SSL pinning error:&#39;, error.serverHostname);<br>  });<br>}</pre><p>You’d typically call this when your app starts — for example, in App.tsx.</p><p>Once that’s done, all your fetch() or XMLHttpRequest calls will automatically enforce the pin.</p><pre>const response = await fetch(&#39;https://api.myserver.com/users&#39;);<br>const data = await response.json();</pre><p>If the certificate doesn’t match your pinned key, the request will fail immediately.</p><blockquote><em>💡 </em><strong><em>Pro Tip:</em></strong><em> Always include a backup public key hash — that way, if you rotate your certificate, you won’t brick your app.</em></blockquote><h3>2. Encrypting Data in React Native</h3><p>Okay, so your network traffic is locked down. But what about your local data?</p><p>React Native’s AsyncStorage is convenient — but it’s <em>plain text</em>. Anyone with access to the device storage could read it. The fix? Encrypt your sensitive data before you store it.</p><h3>Option 1: Roll Your Own With CryptoJS</h3><p>Install CryptoJS:</p><pre>yarn add crypto-js</pre><p>Then wrap your AsyncStorage with some simple encryption helpers:</p><pre>import AsyncStorage from &#39;@react-native-async-storage/async-storage&#39;;<br>import CryptoJS from &#39;crypto-js&#39;;<br><br>const SECRET_KEY = &#39;my_super_secret_key_123&#39;; // don&#39;t hard-code this in production!<br><br>function encrypt(text) {<br>  return CryptoJS.AES.encrypt(text, SECRET_KEY).toString();<br>}<br><br>function decrypt(cipher) {<br>  const bytes = CryptoJS.AES.decrypt(cipher, SECRET_KEY);<br>  return bytes.toString(CryptoJS.enc.Utf8);<br>}<br><br>export async function saveSecure(key, value) {<br>  const encrypted = encrypt(value);<br>  await AsyncStorage.setItem(key, encrypted);<br>}<br><br>export async function loadSecure(key) {<br>  const cipher = await AsyncStorage.getItem(key);<br>  if (!cipher) return null;<br>  return decrypt(cipher);<br>}</pre><p>Usage:</p><pre>await saveSecure(&#39;authToken&#39;, &#39;user-1234-token&#39;);<br>const token = await loadSecure(&#39;authToken&#39;);<br>console.log(&#39;Decrypted token:&#39;, token);</pre><p>This keeps data encrypted on disk. But storing your encryption key inside the code isn’t ideal — in real apps, use <strong>secure storage</strong>.</p><h3>Option 2: Use Secure Storage Libraries</h3><ul><li><a href="https://www.npmjs.com/package/react-native-encrypted-storage"><strong>react-native-encrypted-storage</strong></a> – Encrypts everything and stores it in the OS keychain (recommended).</li><li><a href="https://www.npmjs.com/package/react-native-keychain"><strong>react-native-keychain</strong></a> – Great for storing small secrets like tokens or passwords.</li></ul><p>Example with Encrypted Storage:</p><pre>import EncryptedStorage from &#39;react-native-encrypted-storage&#39;;<br><br>await EncryptedStorage.setItem(&#39;token&#39;, &#39;user-1234-token&#39;);<br>const token = await EncryptedStorage.getItem(&#39;token&#39;);</pre><p>That’s it — no need to manage keys manually.</p><h3>3. Encrypting Payloads (Extra Layer)</h3><p>If you want to go full-fortress mode, you can encrypt your data <em>before</em> sending it over the network — so even your server only sees ciphertext until it decrypts it.</p><pre>import CryptoJS from &#39;crypto-js&#39;;<br><br>const sessionKey = CryptoJS.lib.WordArray.random(32).toString();<br><br>function encryptPayload(obj) {<br>  const json = JSON.stringify(obj);<br>  return CryptoJS.AES.encrypt(json, sessionKey).toString();<br>}<br><br>function decryptPayload(cipher) {<br>  const bytes = CryptoJS.AES.decrypt(cipher, sessionKey);<br>  return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));<br>}<br><br>const body = encryptPayload({ email: &#39;john@doe.com&#39;, password: &#39;1234&#39; });<br>await fetch(&#39;https://api.myserver.com/secure&#39;, {<br>  method: &#39;POST&#39;,<br>  headers: { &#39;Content-Type&#39;: &#39;application/json&#39; },<br>  body: JSON.stringify({ data: body }),<br>});</pre><p>Your server would decrypt it using the same session key. (In production, you’d exchange the key securely via RSA or similar.)</p><h3>3. TrustKit (for Advanced SSL Pinning)</h3><p>When you need more control — reporting, policy customization, or enterprise compliance — <strong>TrustKit</strong> is a great option. It’s the underlying framework that some React Native pinning libraries already use, but you can also integrate it directly for full power.</p><h3>Installing TrustKit</h3><p>For <strong>iOS</strong>, add this to your Podfile:</p><pre>pod &#39;TrustKit&#39;</pre><p>For <strong>Android</strong>, add this to your app/build.gradle:</p><pre>implementation &#39;com.datatheorem.android.trustkit:trustkit:1.1.3&#39;</pre><h3>Setting It Up in React Native</h3><p>In your app initialization (e.g., App.tsx):</p><pre>import { NativeModules } from &#39;react-native&#39;;<br>const { RNTrustKit } = NativeModules;<br><br>RNTrustKit.initWithConfig({<br>  kTSKSwizzleNetworkDelegates: true,<br>  kTSKPinnedDomains: {<br>    &quot;myapi.com&quot;: {<br>      kTSKPublicKeyHashes: [<br>        &quot;HXXQgxueCIU5TTLHob/bPbwcKOKw6DkfsTWYHbxbqTY=&quot;,<br>        &quot;0SDf3cRToyZJaMsoS17oF72VMavLxj/N7WBNasNuiR8=&quot;<br>      ]<br>    }<br>  }<br>});</pre><p>That’s it — now all network calls going through native modules like NSURLSession (iOS) or OkHttp (Android) will validate against your pinned certificates automatically.</p><h3>Real Problem It Solved</h3><p>In one of our projects, we were building a healthcare app that needed strict HIPAA compliance. During testing, we discovered something scary: we could easily intercept all patient data using <strong>Charles Proxy</strong>.</p><p>After implementing <strong>TrustKit</strong>, those intercepted requests failed immediately — the app simply refused to talk to any server that didn’t match the pinned keys.<br> That one change alone made the app compliant and secure against man-in-the-middle attacks.</p><h3>Note on Proxy Tools (Charles, Fiddler, Proxyman)</h3><p>When you’re developing and debugging network calls, proxy tools like <strong>Charles</strong>, <strong>Fiddler</strong>, or <strong>Proxyman</strong> are lifesavers — they let you inspect requests and responses. But SSL pinning intentionally blocks these tools by design. Here’s how to work with that reality without weakening security:</p><ul><li><strong>Understand why pinning blocks proxies</strong>: Proxy tools intercept TLS, acting as a middleman with their own certificate. If your app is pinned to your server’s public key or cert, it will reject the proxy’s certificate — which is good for production security but annoying for debugging.</li><li><strong>Use a debug-only toggle</strong>: Add a build flag or runtime toggle to <em>disable</em> pinning in development builds only. Example pattern: if (__DEV__) initializeSslPinning({ enabled: false }). Never ship a release with pinning disabled.</li><li><strong>Install the proxy cert on device/simulator (limited help)</strong>: For non-pinned apps, you can install the proxy’s CA certificate on a device or simulator to trust it. But for pinned apps, this still won’t work because pinning bypasses the OS trust store.</li><li><strong>Use special dev variants</strong>: Some teams provide a separate dev backend that uses a certificate matching a dev public key pinned into dev builds — this keeps production pins intact while letting dev builds be proxied.</li><li><strong>Simulators vs. real devices</strong>: On iOS simulators it’s usually easier to trust custom CAs; on real devices you must explicitly trust the installed CA under Settings. Android has more pitfalls because apps can opt out of the system trust store via Network Security Config.</li><li><strong>Log and simulate</strong>: When pinning makes inspection impossible, add well-instrumented logs or temporarily return verbose error info from your dev server to help debugging without relying on a proxy.</li><li><strong>Be careful with secrets</strong>: If you temporarily disable pinning for debugging, make sure any sensitive data (keys, real user data) is not exposed in logs or on the proxy to avoid accidental leaks.</li></ul><p>In short: prefer dev-only exceptions or a dedicated dev build. Don’t weaken production security just to make debugging easier.</p><h3>Best Practices and Gotchas</h3><p>🔄 <strong>Handle key rotation</strong> — Always include a backup public key hash.</p><p>🧠 <strong>Never hard-code keys</strong> — Store them securely in Keychain or Keystore.</p><p>⚡ <strong>Disable pinning for debug builds</strong> — It can block tools like Charles Proxy.</p><p>🧩 <strong>Test error scenarios</strong> — Make sure your app fails gracefully when pinning fails.</p><p>🧱 <strong>Encrypt only what’s needed</strong> — Encrypt tokens, not every piece of app data.</p><h3>Wrapping Up</h3><p>Security isn’t something you “add later.” The best time to implement it is <em>before</em> something goes wrong. With SSL pinning and data encryption in React Native, you’re making it exponentially harder for attackers to eavesdrop, tamper, or steal user data.</p><p>Start with these basics:</p><ol><li>Add SSL pinning with react-native-ssl-public-key-pinning.</li><li>Encrypt your local storage using react-native-encrypted-storage or crypto-js.</li><li>Plan ahead for certificate and key rotation.</li></ol><p>Small steps, big difference. 🔐</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4205e0ad67ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Download a string as a (.txt) file in React?]]></title>
            <link>https://medium.com/@iyiolaosuagwu/download-a-string-as-a-txt-file-in-react-7d55efb22536?source=rss-a5d9a8c339cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d55efb22536</guid>
            <dc:creator><![CDATA[iyiola osuagwu]]></dc:creator>
            <pubDate>Tue, 11 Jan 2022 21:44:52 GMT</pubDate>
            <atom:updated>2022-01-12T06:37:46.314Z</atom:updated>
            <content:encoded><![CDATA[<p><em>I started my day with a list of tasks one of which was to convert an API response data to a downloadable txt file in React. In this article, we’ll take a look at a basic example of how to download a string as a .txt file in React.</em></p><p><em>To download a string as a .txt file in React, we can convert the string into a blob.</em></p><p><em>And then we can create a hidden link that has the blob’s object URL set as the href attribute and click on the link programmatically to download it.</em></p><p><em>To illustrate this, we write:</em></p><pre><em>import React from &quot;react&quot;;<br><br>export default function App() {<br>  const handleFileDownload = () =&gt; {<br>    const element = document.createElement(&quot;a&quot;);<br>    const file = new Blob([&quot;hello world&quot;], {<br>      type: &quot;text/plain&quot;<br>    });<br>    element.href = URL.createObjectURL(file);<br>    element.download = &quot;myFile.txt&quot;;<br>    document.body.appendChild(element);<br>    element.click();<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={handleFileDownload}&gt;Download File&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</em></pre><blockquote><strong>What is Blob in javascript</strong></blockquote><p><em>The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data or converted into a ReadableStream so its methods can be used for processing the data. Blobs can represent data that isn’t necessarily in a JavaScript-native format.</em></p><p><em>to define the </em><em>handleFileDownload function to put the </em><em>‘hello world’ string in a blob and download that as a text file.</em></p><p><em>In the function, we create an </em><em>a element with </em><em>document.createElement.</em></p><p><em>Next, we define a blob with </em><em>&#39;hello world&#39; as its content with the </em><em>Blob constructor.</em></p><p><em>We set the </em><em>type property to </em><em>&#39;text/plain&#39; to make the downloaded file a text file.</em></p><p><em>Next, we set </em><em>element.href to the object URL version of the blob that we create with </em><em>URL.createObjectURL.</em></p><p><em>And we set the file name of the downloaded file by setting the </em><em>element.download property.</em></p><p><em>Next, we call </em><em>document.body.appendChild with the link </em><em>element to attach it to the body.</em></p><p><em>Finally, we call </em><em>element.click to click on the hidden link to download the file.</em></p><h3>Conclusion</h3><p><em>To download a string as a .txt file in React, we can convert the string into a blob.</em></p><p><em>And then we can create a hidden link that has the blob’s object URL set as the href attribute and click on the link programmatically to download it.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d55efb22536" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>