<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>application security &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/application-security/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 01 Sep 2026 19:26:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.7</generator>
	<item>
		<title>Protect Passwords, Tokens, Requests, and Updates with the Crypto Module</title>
		<link>https://blog.xojo.com/2026/09/01/protect-passwords-tokens-requests-and-updates-with-the-crypto-module/</link>
		
		<dc:creator><![CDATA[Gabriel Ludosanu]]></dc:creator>
		<pubDate>Tue, 01 Sep 2026 22:04:00 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[AES]]></category>
		<category><![CDATA[application security]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Ed25519]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Hashing]]></category>
		<category><![CDATA[HMAC]]></category>
		<category><![CDATA[PBKDF2]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=16507</guid>

					<description><![CDATA[The&#160;Crypto&#160;module covers several different jobs. The hard part is usually not finding a function; it is choosing the right one for the problem in front&#8230;]]></description>
										<content:encoded><![CDATA[
<p>The&nbsp;<a href="https://documentation.xojo.com/api/cryptography/crypto.html" target="_blank" rel="noreferrer noopener"><code>Crypto</code></a>&nbsp;module covers several different jobs. The hard part is usually not finding a function; it is choosing the right one for the problem in front of you.</p>



<p>Which function should you use when your app needs to:</p>



<ul class="wp-block-list">
<li>remember a user&#8217;s password,</li>



<li>save an API token in a local settings file,</li>



<li>check that an API request was not changed, or</li>



<li>verify that an update came from you?</li>
</ul>



<pre class="wp-block-preformatted">The examples below answer those questions with small, focused scenarios. They show where each function fits. They are not complete security products.</pre>



<p>A good starting point is:</p>



<ul class="wp-block-list">
<li>Use&nbsp;<a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-pbkdf2" target="_blank" rel="noreferrer noopener"><strong>PBKDF2</strong></a>&nbsp;when you need to check a password later.</li>



<li>Use&nbsp;<a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-aesencrypt" target="_blank" rel="noreferrer noopener"><strong>AES</strong></a>&nbsp;when you need to hide data that your app must read again.</li>



<li>Use&nbsp;<a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-hmac" target="_blank" rel="noreferrer noopener"><strong>HMAC</strong></a>&nbsp;when two trusted systems share a secret and need to detect changed messages.</li>



<li>Use&nbsp;<a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-ed25519generatekeypair" target="_blank" rel="noreferrer noopener"><strong>Ed25519</strong></a>&nbsp;when one side signs data and other parties only need to verify it.</li>
</ul>



<h2 class="wp-block-heading" id="example-1-remembering-a-users-password-with-pbkdf2">Example 1: Remembering a user&#8217;s password with PBKDF2</h2>



<p>Imagine a desktop or web app with a login screen. When a user creates an account, you need to save something that lets you check the password later.</p>



<pre class="wp-block-preformatted">Do not save this:&nbsp;correct horse battery staple</pre>



<p>If somebody gets the database, they immediately have the user&#8217;s password. A plain SHA-256 hash is not a good replacement because attackers can calculate fast hashes very quickly and try large lists of common passwords. PBKDF2 is designed for this job. It combines the password with a random salt and repeats the calculation many times.</p>



<pre class="wp-block-code"><code>Var password As String = "correct horse battery staple"
Var salt As String = EncodeHex(Crypto.GenerateRandomBytes(16))
Var iterations As Integer = 100000
Var derived As MemoryBlock = Crypto.PBKDF2(salt, password, iterations, 32, Crypto.HashAlgorithms.SHA2_512)
Var storedHash As String = EncodeHex(derived)</code></pre>



<p>Save&nbsp;<code>salt</code>,&nbsp;<code>iterations</code>, the algorithm name, and&nbsp;<code>storedHash</code>&nbsp;in the user&#8217;s record. The salt does not need to be secret. You need it again when the user logs in.</p>



<pre class="wp-block-code"><code>Var suppliedPassword As String = "correct horse battery staple"
Var calculated As MemoryBlock = Crypto.PBKDF2(salt, suppliedPassword, iterations, 32, Crypto.HashAlgorithms.SHA2_512)
Var calculatedHash As String = EncodeHex(calculated)

If calculatedHash = storedHash Then
  MessageBox("Password accepted")
Else
  MessageBox("Password rejected")
End If</code></pre>



<p>The app never needs to recover the original password. It calculates the value again and compares it with the stored one.</p>



<p>The iteration count in this example is only an example. Test it on the slowest computer you support. Store the count with the hash so you can increase it later and update old records after a successful login.</p>



<p>Use&nbsp;<code>Crypto.GenerateRandomBytes</code>&nbsp;here because the salt must not be predictable. The same function is useful when you need a random token, nonce, or initialization vector.</p>



<h2 class="wp-block-heading" id="example-2-saving-an-api-token-in-an-encrypted-settings-file">Example 2: Saving an API token in an encrypted settings file</h2>



<p>Now imagine a desktop app that lets a user connect to an online service. After the user enters an API token, the app should remember it without saving readable text to its settings file.</p>



<p>This is a job for symmetric encryption. The app uses the same secret key to encrypt and decrypt the value.</p>



<p>AES accepts keys that are 16, 24, or 32 bytes long. The initialization vector is 16 bytes for AES. This example uses a 32-byte key and a new 16-byte IV:</p>



<pre class="wp-block-code"><code>Var secretKey As String = Crypto.GenerateRandomBytes(32)
Var initializationVector As MemoryBlock = Crypto.GenerateRandomBytes(16)
Var apiToken As String = "token-from-the-service"
Var encryptedToken As MemoryBlock = Crypto.AESEncrypt(secretKey, apiToken, Crypto.BlockModes.CBC, initializationVector)</code></pre>



<p>To read the token later:</p>



<pre class="wp-block-code"><code>Var decryptedToken As MemoryBlock = Crypto.AESDecrypt(secretKey, encryptedToken, Crypto.BlockModes.CBC, initializationVector)
Var apiTokenAgain As String = decryptedToken</code></pre>



<p>The IV is not a password and does not need to be secret. Save it with the encrypted value. You need the same IV for decryption.</p>



<p>The key is the difficult part. If you generate a new key every time the app starts, the app cannot decrypt yesterday&#8217;s settings. A real application must store the key in a suitable secret store, derive it from a user-provided secret, or keep the sensitive value on a server. Do not put a production key directly in the source code.</p>



<p>The encrypted record might contain these fields:</p>



<pre class="wp-block-code"><code>version
iv
ciphertext</code></pre>



<p>Store the IV and ciphertext as Base64 or hexadecimal text if the settings format cannot hold binary data. Store a version so you can change the format later.</p>



<p>CBC encryption hides the token, but it does not prove that the ciphertext was not changed. For real data, authenticate the encrypted record as well. With CBC, that means using an encrypt-then-MAC design with a separate MAC key. Another option is a vetted authenticated-encryption library or a service that provides an AEAD mode.</p>



<p>Do not reuse an IV with the same key, and do not use ECB mode for application data.</p>



<h2 class="wp-block-heading" id="example-3-signing-an-api-request-with-hmac">Example 3: Signing an API request with HMAC</h2>



<p>Suppose you control both a client and a server application. The client sends an order to the server, and the server needs to know whether somebody changed the request while it was being sent.</p>



<p>The client and server can share a secret. The client signs the request with HMAC, and the server calculates the same HMAC. If the values differ, the server rejects the request.</p>



<pre class="wp-block-code"><code>Var sharedSecret As String = "replace-this-with-a-real-secret"
Var requestText As String = "POST|/api/orders|1714492800|{""id"":42}"
Var requestData As MemoryBlock = requestText
Var signature As MemoryBlock = Crypto.HMAC(sharedSecret, requestData, Crypto.HashAlgorithms.SHA2_256)
Var signatureText As String = EncodeBase64(signature)</code></pre>



<p>Send&nbsp;<code>requestText</code>&nbsp;and&nbsp;<code>signatureText</code>&nbsp;to the server. The server must build exactly the same text before calculating its own signature. A different separator, line ending, or JSON layout produces a different result.</p>



<p>A signature by itself does not stop somebody from sending the same valid request again. Include a timestamp and reject requests that are too old. For an operation that must only happen once, include a unique request ID and record IDs that the server has already processed.</p>



<p>HMAC is a good fit for two backend services or a controlled client-server arrangement. It is a poor fit when you ship the shared secret inside an untrusted desktop or mobile app. A secret compiled into an app can eventually be extracted.</p>



<h2 class="wp-block-heading" id="example-4-verifying-an-update-with-ed25519">Example 4: Verifying an update with Ed25519</h2>



<p>A different situation comes up when you distribute application updates. The update server should be able to sign a file, but the installed app should only need to verify it. The installed app should not possess a secret that could create fake signatures.</p>



<p>Use a public and private key pair:</p>



<ul class="wp-block-list">
<li>Keep the private key on the signing machine.</li>



<li>Put the public key in the application or distribute it through a trusted channel.</li>
</ul>



<pre class="wp-block-code"><code>Var privateKey As String
Var publicKey As String

If Crypto.ED25519GenerateKeyPair(privateKey, publicKey) Then
  Var updateInfo As String = "version=4.2.1|sha256=..."
  Var signature As MemoryBlock = Crypto.ED25519Sign(updateInfo, privateKey)

  If signature &lt;&gt; Nil And Crypto.ED25519VerifySignature(updateInfo, signature, publicKey) Then
    MessageBox("Update information is authentic")
  End If
End If</code></pre>



<p>In a real updater, verify the signature before trusting the version or downloading the file. The signature does not prove that the update is safe by itself. It proves that the data matches the private key associated with the public key.</p>



<p>Keep the exact bytes stable. If the signing tool adds a line ending but the app removes it before verification, the signature will fail.</p>



<h2 class="wp-block-heading" id="which-function-solves-which-problem">Which function solves which problem?</h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">Problem</th><th class="has-text-align-left" data-align="left">Use</th><th class="has-text-align-left" data-align="left">What you store or send</th></tr></thead><tbody><tr><td>Check a password later</td><td><code>Crypto.PBKDF2</code></td><td>Salt, iteration count, algorithm, derived value</td></tr><tr><td>Create an unpredictable salt or IV</td><td><code>Crypto.GenerateRandomBytes</code></td><td>The salt or IV, when the operation needs it later</td></tr><tr><td>Hide data that your app must decrypt</td><td><code>Crypto.AESEncrypt</code>&nbsp;and&nbsp;<code>Crypto.AESDecrypt</code></td><td>Key, IV, and ciphertext, using a safe storage design</td></tr><tr><td>Detect changes to a shared-secret request</td><td><code>Crypto.HMAC</code></td><td>Message and HMAC value</td></tr><tr><td>Verify data signed by another system</td><td><code>Crypto.ED25519Sign</code>&nbsp;and&nbsp;<code>Crypto.ED25519VerifySignature</code></td><td>Signature and public key</td></tr><tr><td>Create a fixed fingerprint of public data</td><td><code>Crypto.Hash</code></td><td>The expected hash from a trusted source</td></tr></tbody></table></figure>



<p>Start with the problem, not the function name. Ask what the other side needs to do:</p>



<ul class="wp-block-list">
<li>Does it need to check a password? Use PBKDF2.</li>



<li>Does it need to read the original data? Use encryption.</li>



<li>Does it need to detect a changed message and share a secret with the sender? Use HMAC.</li>



<li>Does it need to verify a message without being able to create signatures? Use a public-key signature.</li>
</ul>



<h2 class="wp-block-heading" id="a-short-safety-checklist">A short safety checklist</h2>



<ol class="wp-block-list">
<li>Never store plaintext passwords.</li>



<li>Do not use a fast general-purpose hash as a password-storage scheme.</li>



<li>Do not hard-code production secrets in source code or a desktop application.</li>



<li>Generate salts and IVs with&nbsp;<code>Crypto.GenerateRandomBytes</code>.</li>



<li>Use&nbsp;<code>SHA2_256</code>&nbsp;or stronger for new hashes and HMACs. Avoid MD5 and SHA-1 for new security designs.</li>



<li>Do not treat AES-CBC ciphertext as authenticated unless you add an integrity check.</li>



<li>Keep the exact bytes being signed stable.</li>



<li>Test wrong passwords, wrong keys, changed messages, replayed requests, and corrupted ciphertext.</li>



<li>Check the Xojo compatibility notes for every algorithm you choose.</li>



<li>Use an established format or library instead of inventing a cryptographic protocol.</li>
</ol>



<p>The&nbsp;<code>Crypto</code>&nbsp;module gives you the operations. Your application still has to decide where keys live, what gets signed, how data is formatted, and how keys are replaced. Those decisions determine whether the example can grow into something you can support.</p>



<p><em>Gabriel is a digital marketing enthusiast who loves coding with Xojo to create cool software tools for any platform. He is always eager to learn and share new ideas!</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Using Public/Private Key Encryption in Xojo</title>
		<link>https://blog.xojo.com/2014/02/05/using-publicprivate-key-encryption-in-xojo/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Wed, 05 Feb 2014 00:00:00 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[AES]]></category>
		<category><![CDATA[application security]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Encryption]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2014/02/05/using-publicprivate-key-encryption-in-xojo/</guid>

					<description><![CDATA[Using Public/Private Key Encryption in Xojo]]></description>
										<content:encoded><![CDATA[<p><span style="line-height: 1.62;">Xojo 2013 Release 4.1 added a variety of RSA encryption functions for handling public/private key encryption. Here&#8217;s how you use them.</span></p>
<p><span id="more-98"></span></p>
<p>Here is the problem: How can you send a small message to me so that only I can read it? A technique called <a href="http://en.wikipedia.org/wiki/Public-key_cryptography">Public Key Cryptography</a> is commonly used for this.</p>
<h2>RSA Public Key Encryption</h2>
<p>With Public Key Cryptography there are two keys: a public key and a private key. Since I am the one receiving messages, I would generate both of these keys. This can be done in Xojo using the Crypto.RSAGenerateKeyPair function:</p>
<pre>Dim privateKey As StringDim publicKey As String</pre>
<pre>If Crypto.RSAGenerateKeyPair(1024, privateKey, publicKey) Then
  // 1024-bit private and public keys were generated
End If</pre>
<p><span style="line-height: 1.62;">I keep the private key to myself and do not share it with anyone. The public key is shared with you (or anyone, really). To make the public key more presentable, converting it to Base64 is a good idea:</span></p>
<pre>viewablePublicKey = EncodeBase64(publicKey)</pre>
<p>Here is a public key that I created (Base64 encoded):</p>
<pre><span style="font-size: 13px;">MzA4MTlEMzAwRDA2MDkyQTg2NDg4NkY3MEQwMTAxMDEwNTAwMDM4MThCMDAzMDgxODcwMjgxODEwMEJGRDg2QTkzQkUzNjlFQTE2MDA2QTg2OTFGQkY2MTM5QTc2QkNGNDcwQUY0RjUzMjkyQjJEOUVEMEE2QzRENzIzRDRGMTRCRDY4Nzk4MkQ2QjEyNDVFNkU2QTEwRUNFNThCMzc2MUYyNDJFOTQyQTI1Q0ZGMjk0NzM3QUQ2MkVBRkU3RkU4NkFDNDBDNTMzODIxQzI0QkY4MjBGNTgxMjE2MEU5REE5OEI2RkEyQjY2NUZCN0Q5NEYyN0Q1MTIwMTQ1REU1NUY0MEQ3MDY5NTQzQ0FEOTI0MUE0MUFFMkRDNzJFQTRGN0FDRkFGNzQ5NkNDOUIwQTVFMkNDRkVCMDkwMjAxMTE=</span></pre>
<p><span style="line-height: 1.62;">The public key is used to encrypt the message. </span><span style="line-height: 1.62;">In Xojo, it is done like this:</span></p>
<pre>Dim publicKey As String = DecodeBase64(PublicKeyArea.Text)
Dim textMessage As String = "Top-secret message for Paul."
Dim msg As MemoryBlockmsg = textMessage
// Encrypt msg using the publicKey
Dim encryptedData As MemoryBlock = Crypto.RSAEncrypt(msg, publicKey)
If encryptedData &lt;&gt; Nil Then
  MsgBox("Successfully encrypted.")
End If</pre>
<p><span style="line-height: 1.62;">Now you have an encrypted message that you can Base64Encode and send to me:</span></p>
<pre>Dim msgForPaul As String = EncodeBase64(encryptedData)</pre>
<p>You can paste this message in an email or even put in a a public forum. No one else will be able to read it. To decrypt it, the private key is needed and only I have the private key.</p>
<p>Xojo code to decrypt the message looks like this:</p>
<pre>encryptedData = DecodeBase64(encryptedMsgForPaul)
Dim decryptedData As MemoryBlock = Crypto.RSADecrypt(encryptedData, privateKey)
Dim msg As String = decryptedData
MsgBox(msg)</pre>
<p>Try the CryptoRSAExample (Examples/Framework) included with Xojo to see this in action.</p>
<p>To test this out, use RSAEncryptor with the above Public Key to leave me encrypted messages in the comments. I&#8217;ll decrypt it and post the decrypted version as a reply. Keep in mind that these &#8220;messages&#8221; that are being encrypted have to be pretty short (just a couple hundred characters to be safe). This is due to the complex mathematics involved in the generation of the data and it is way beyond anything I can understand, let alone explain. So typically this means that you do not use the above techniques for communicating lengthy messages. More typically these techniques are used to communicate another &#8220;secret key&#8221; of some kind that can be used to decrypt the actual message that was encrypted with some other technique.</p>
<p>For example, I could create a SQLite database that is encrypted in Xojo and then send you the database. This would be encrypted using AES-128. But how do you decrypt it to access its data since you&#8217;ll need the password to decrypt it? This is a perfect situation to use RSA to encrypt the password for the recipient to decrypt. Once they have decrypted the RSA message to get the password, it can be used to access the database. So the process for Julie to send an encrypted database to Paul is as follows:</p>
<p>1. Julie creates a SQLite database, adds data to it and encrypts it using a secret password.</p>
<p>2. Paul creates an RSA Public/Private key pair and gets the Public Key to Julie.</p>
<p>3. Julie encrypts the secret password using the Public Key from Paul to get an encrypted message that she sends to Paul.</p>
<p>4. Paul can decrypt the message from Julie using his Private Key to get the secret password.</p>
<p>5. Julie sends the encrypted database to Paul.</p>
<p>6. Paul accesses the database using the secret password he now has from step 4.</p>
<p>This is secure because the database cannot be accessed by anyone that does not have the secret password and only the person with the RSA Private Key pair for the Public Key used to encrypt the secret password will be able to decrypt it to open the database.</p>
<h2>Signatures</h2>
<p><span style="line-height: 1.62;">Related to all this is the concept of signatures. A signature is used so that you can validate who sent a message and that the message was not modified before it reached you.</span></p>
<p><span style="line-height: 1.62;">To do this, I sign my message using my Private Key (as generated above) and provide you with both the message and the signature. You then verify everything using my Public Key.</span></p>
<p><span style="line-height: 1.62;">This is how I would sign a message using Xojo:</span></p>
<pre>Dim signature As MemoryBlock = Crypto.RSASign(msg, privateKey)</pre>
<p><span style="line-height: 1.62;">You would then verify the message and signature using my Public Key:</span></p>
<pre>If Crypto.RSAVerifySignature(msg, signature, publicKey) Then
  // msg is valid
End If</pre>
<p>The &#8220;message&#8221; can actually be any data. For example, this is essentially what you are doing when you &#8220;code-sign&#8221; an application for OS X.</p>
<p>Try the CryptoRSAExample (Examples/Framework) included with Xojo to see this in action.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
