<?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>Crypto &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/crypto/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.8</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>Crypto Improvements</title>
		<link>https://blog.xojo.com/2021/11/18/crypto-improvements/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Thu, 18 Nov 2021 12:40:00 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=9589</guid>

					<description><![CDATA[Xojo 2021 Release 3 has a few improvements to the Crypto module that you might find useful such as SHA3, BlowFish/TwoFish and CRC-32.]]></description>
										<content:encoded><![CDATA[
<p>Xojo 2021 Release 3 has a few improvements to the <a href="https://documentation.xojo.com/api/cryptography/crypto.html">Crypto</a> module that you might find useful.</p>



<h3 class="wp-block-heading">SHA3</h3>



<p>A new <a href="https://en.wikipedia.org/wiki/SHA-3">SHA3</a> algorithm is available for use with the Hash function. You can now use SHA3-256 (SHA3 with 256-bit digest) and SHA3-512 (SHA3 with a 512 bit digest) from the <a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-hashalgorithms">Crypto.HashAlgorithms</a> enumeration for stronger encryption or compatibility with something else that uses them.</p>



<pre class="wp-block-preformatted">Var hash As String
hash = Crypto.Hash("YourPasswordSentence", Crypto.HashAlgorithms.SHA3_512)</pre>



<h3 class="wp-block-heading">BlowFish / TwoFish</h3>



<p>The BlowFish and TwoFish encryption algorithms can now be used in Xojo. These two algorithms are similar, with <a href="https://en.wikipedia.org/wiki/Blowfish_(cipher)">BlowFish</a> being the original algorithm and <a href="https://en.wikipedia.org/wiki/Twofish">TwoFish</a> being a newer, more secure version that was derived from BlowFish.</p>



<p>You can use them in Xojo with the <a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-blowfishencrypt">Crypto.BlowFishEncrypt</a>, <a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-blowfishdecrypt">Crypto.BlowFishDecrypt</a>, <a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-twofishencrypt">Crypto.TwoFishEncrypt</a> and <a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-twofishdecrypt">Crypto.TwoFishDecrypt</a> methods.</p>



<p>You can use either to encrypt data, but in general you&#8217;ll want to avoid BlowFish for your own code, although it might prove useful for compatibility with other libraries or tools.</p>



<h3 class="wp-block-heading">AES</h3>



<p>AES (Advanced Encryption Standard) is also used to encrypt data. You can do this using the <a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-aesencrypt">Crypto.AESEncrypt</a> and <a href="https://documentation.xojo.com/api/cryptography/crypto.html#crypto-aesencrypt">Crypto.AESDecrypt</a> methods. Here is a quick sample:</p>



<pre class="wp-block-preformatted">Var encrypted As MemoryBlock

Var dataToEncrypt As MemoryBlock = "Secret!"
Var key As MemoryBlock = Crypto.GenerateRandomBytes(16)
Var initVector As MemoryBlock = Crypto.GenerateRandomBytes(16)
encrypted = Crypto.AESEncrypt(key, dataToEncrypt, Crypto.BlockModes.CBC, initVector)

Var decrypted As MemoryBlock
decrypted = Crypto.AESDecrypt(key, encrypted, Crypto.BlockModes.CBC, initVector)
// decrypted = "Secret!"</pre>



<p></p>



<h3 class="wp-block-heading">CRC-32</h3>



<p>CRC32 is just a simple way to test data integrity and is not cryptographically secure. It still has its uses for fast data comparison and simple hash tables. It can be called like this:</p>



<pre class="wp-block-preformatted">Var crc32 As String
crc32 = Crypto.Hash("StringOrDataToTest", Crypto.HashAlgorithms.CRC32)</pre>



<h3 class="wp-block-heading">RSASign</h3>



<p>RSASign now takes an optional parameter and RSASignModes let you specify the hash to use.</p>



<p>Learn more about the Crypto module in the <a href="https://documentation.xojo.com/api/cryptography/crypto.html">Xojo Documentation</a>.</p>



<p></p>



<p>Updated (Nov 22, 2021): Added AES section</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A compromise to security is always just that.</title>
		<link>https://blog.xojo.com/2017/08/28/a-compromise-to-security-is-always-just-that/</link>
		
		<dc:creator><![CDATA[Geoff Perlman]]></dc:creator>
		<pubDate>Mon, 28 Aug 2017 18:22:02 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Mobile]]></category>
		<guid isPermaLink="false">http://blog.xojo.com/?p=3192</guid>

					<description><![CDATA[Governments debate requiring companies to build "backdoors" into their technology. The problem is that if the government or the company can get in, others will inevitably find a way to exploit that same back door too, making us and our data less safe and secure.]]></description>
										<content:encoded><![CDATA[<p>Last month the Australian government <a href="https://www.macobserver.com/news/australia-attorney-general-apple-encryption-back-door/">suggested</a> they might require tech companies to provide back doors into their systems to help law enforcement use those back doors to catch bad guys. Apple immediately dispatched people to go talk with them about it. Apple&#8217;s stance has been that such back doors don&#8217;t help catch bad guys and just make the rest of us less secure. Is that really true?</p>
<p><span id="more-3192"></span></p>
<p>Systems like Apple&#8217;s iMessage (their text messaging service) use encryption ensuring that all messages sent between Apple devices via iMessage are encrypted with keys that Apple does not have. They keys are on your device. Law enforcement agencies want Apple and others to provide a means of decrypting those messages without having to obtain the device itself. <strong>The problem is that if the government and Apple can get in, others will inevitably find a way to exploit that same back door too, making us and our data less safe and secure.</strong></p>
<p>What some governments have failed to understand is that the bad guys can bypass any back door by using their own encryption. The smart bad guys probably assume that these back doors exist now (or at least aren&#8217;t taking any chances) and are already using their own encryption for their communications. How hard is it to write software to encrypt and decrypt messages? Do bad guys have access to programmers smart enough to do this? Yes, they almost certainly do.</p>
<p>Let&#8217;s take a look at what is involved in using <a href="http://www.xojo.com">Xojo</a> to write an app that encrypts and decrypts messages. First, two keys need to be generated, a public key and a private one. The public key allows anyone to encrypt a message that only the holder of the matching private key can decrypt. Public keys can only encrypt. They are no good for decrypting messages. This means you can give anyone your public key which they can then use to send encrypted messages to you that no one else but you can decrypt.</p>
<pre>Dim privateKey As String
Dim publicKey As String
If Crypto.RSAGenerateKeyPair(KeySize, privateKey, publicKey) Then
 PrivKey.Text = privateKey
 PubKey.Text = publickey
 SaveNewKeys(privateKey, publicKey)
Else
 Beep
 MsgBox "An error has occured. Keys could not be generated."
End If
</pre>
<p>This is just 10 lines of code and it could be further reduced. I wrote this to make it easier to read. The important function is RSAGenerateKeyPair on the third line. Next, you need to be able to encrypt a message using someone else&#8217;s public key. Let&#8217;s take a look at the code to do that:</p>
<pre>Dim publicKey As String = RecipientsPublicKey.Text
Dim msg As MemoryBlock = OriginalMessage.Text
try
 Dim encryptedData As MemoryBlock = Crypto.RSAEncrypt(msg, publicKey)
 beep
 If encryptedData = Nil Then
  MsgBox("Encryption failed.")
 else
  Dim c As New Clipboard
  c.Text = Encodebase64(encryptedData)
  c.close
  MsgBox("Your encrypted message has been copied to the clipboard.")
 End If
Catch rte As RuntimeException
 If rte IsA CryptoException Then
  Beep
  MsgBox "Encryption failed because the Public key provided is not valid."
 Else
  Raise rte
 End If
End Try</pre>
<p>This is 21 lines of code, most of which is handling errors. The one line that is really doing the work is the fourth one that contains RSAEncrypt. Next we need to be be able to decrypt. Here&#8217;s what that code looks like:</p>
<pre>Dim privateKey As String = privKey.Text
try
 Dim decryptedData As MemoryBlock = Crypto.RSADecrypt(DecodeBase64(EncryptedMessage.Text), privateKey)
 Decryptedmessage.Text = DefineEncoding(decryptedData.StringValue(0, decryptedData.size), Encodings.UTF8)
Catch rte As RuntimeException
 If rte IsA CryptoException Then
 Beep
 MsgBox "The message could not be decrypted because the incorrect key was provided."
 Else
 Raise rte
 End If
End Try</pre>
<p>This is 12 lines of code and like the other code examples, is mostly error checking. The important line is the third one that calls RSADecrypt. There is some additional code to save the keys to a text file and load them back in automatically when the app is launched. However, even adding in all that code gets you to only about 80 lines total. <strong>In other words, this is not a big app and not beyond the ability of someone with intermediate programming skills or even perhaps a very dedicated novice.</strong> (To learn about this in more depth, read <a href="http://blog.xojo.com/2014/02/05/using-publicprivate-key-encryption-in-xojo/">Using Public/Private Key Encryption in Xojo</a>).</p>
<p>If you&#8217;d like to try out encrypting messages with the app from which the code above originated, you can download <a href="http://blog.xojo.com/wp-content/uploads/2017/08/CryptoMessage-Mac.zip">CryptoMessage for macOS</a>, <a href="http://blog.xojo.com/wp-content/uploads/2017/08/CryptoMessage-Windows.zip">CryptoMessage for Windows</a> or <a href="http://blog.xojo.com/wp-content/uploads/2017/08/CryptoMessage-Linux.zip">CryptoMessage for Linux</a>. Have a friend do it as well and you can send encrypted messages back and forth. If you&#8217;re more adventurous and would like to try playing around with the source code itself, make sure you have <a href="http://www.xojo.com">Xojo</a> installed (which can be <a href="http://www.xojo.com/download">downloaded</a> and used for free) then download the <a href="http://blog.xojo.com/wp-content/uploads/2017/08/CryptoMessage.zip">CryptoMessage Xojo Project</a>.</p>
<p>Xojo has a <a href="http://developer.xojo.com/xojo-crypto">crypto library</a> (the part that provides key generation, encryption and decryption) built-in to it. However, if a programmer wasn&#8217;t using Xojo, they could easily find a crypto library on the Internet to use. In other words, building your own app to encrypt and decrypt messages is not very challenging. As I mentioned earlier, the bad guys (at least the smart ones) are likely already doing this as they are probably sufficiently paranoid that despite public announcements to the contrary, the back doors already exist.</p>
<p><strong>The assumption that compromising our security enables catching more bad guys is a flawed one that I have <a href="http://blog.xojo.com/2016/01/27/smartphone-encryption-is-a-red-herring/">written about</a> <a href="http://blog.xojo.com/2016/02/04/if-smartphone-encryption-is-a-red-herring-how-do-we-track-the-bad-guys/">before</a>.</strong> It won&#8217;t work and we will all suffer needlessly. Imagine not being able to carry on a private conversation via your smartphone. That would make your device feel <strong>a lot</strong> less useful. Some governments have &#8220;experts&#8221; that have suggested it would be possible to have a back door Law Enforcement could use but could not be compromised by anyone else. That is a logical impossibility. Governments do not possess magic powers. They are made of up people like you and me. That is wishful thinking at best and negligent at worse.</p>
<p>When your government starts making noises about doing this, I advise you to make it clear to them that for the reasons I have stated in this post, such a compromising security is all downside with no upside at all.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>RSA: Private/Public keys between Xojo and PHP</title>
		<link>https://blog.xojo.com/2017/06/06/rsa-privatepublic-keys-between-xojo-and-php/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Tue, 06 Jun 2017 04:37:26 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[AprendeXojo]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSA]]></category>
		<guid isPermaLink="false">http://blog.xojo.com/?p=2767</guid>

					<description><![CDATA[Among other topics, Cryptography and data ciphering always fascinated me. Beyond their mathematical perspective, most of the time it is a matter of putting them&#8230;]]></description>
										<content:encoded><![CDATA[<p>Among other topics, Cryptography and data ciphering always fascinated me. Beyond their mathematical perspective, most of the time it is a matter of putting them in practice with developed solutions: dealing with data only visible between the transmitter and the receiver. As it happens, the Xojo framework makes it really easy to deal with ciphered data.<span id="more-2767"></span></p>
<p>All the methods related to cryptography and data ciphering are available under the <a href="http://developer.xojo.com/xojo-crypto"><b>Crypto</b></a> module of Xojo, using behind the scene the Crypto++ 5.6.3 library. From the practical side, this allows us to use the <strong>RSA</strong> public key ciphering and other algorithms to compute unique footprints for given data, as for example <a href="http://developer.xojo.com/xojo-crypto$Hash"><b>Hash</b></a>, <a href="http://developer.xojo.com/xojo-crypto$MD5"><b>MD5</b></a> or <a href="http://developer.xojo.com/xojo-crypto$SHA1"><b>SHA</b></a>. <a href="https://blog.xojo.com/2014/02/05/using-publicprivate-key-encryption-in-xojo/">Paul blogged</a> about using Public/Private Key Encryption in Xojo back when we added RSA encryption functions in 2014.</p>
<p>Among the methods related to RSA, we can find the ones to create the Private/Public keys, test the integrity of the public key, signing the given data and, of course, check the integrity of the signature, and ciphering / deciphering the given group of data.</p>
<p>As you probably already know, when we work with RSA we have to keep the Private key in a safe place, using the Public one to give to other people/service/app to whom we want to share information with in a safe manner. This way the users and/or apps and services will be able to use our public key to cipher the data that they want to share with us, and we will be able to use our private key to decipher that group of data so it is <em>legible</em> again.</p>
<h1>RSA: Creating and interchanging the keys</h1>
<p>Generating the pair of keys could not be more easy in Xojo, with this snippet of code:</p>
<pre>Dim publicKey As String
Dim privateKey As String
If Crypto.RSAGenerateKeyPair( 1024, privateKey, publicKey ) Then msgBox “Successfully generated Keys!"</pre>
<p>As you can see, the <a href="http://developer.xojo.com/xojo-crypto$RSAGenerateKeyPair"><b>RSAGenerateKeyPair</b></a> method receives the Integer number that indicates the strength (robustness) of the generated keys, followed by the String variables containing the generated Private and Public keys, passed by reference.</p>
<p>But in some cases it is possible that you want to use these keys beyond the scope of Xojo, for example when integrating your app with a service or solution developed in PHP. In these cases you have to consider that the keys generated with Xojo are in hexadecimal format.</p>
<p>What does this mean? Well, a public key generated with Xojo will look like this chunk of data:</p>
<pre>30819D300D06092A864886F70D010101050003818B0030818702818100B4B531D3402C250D8640E739601F01FBE8ABB39635BE1778A7F4E55C49419C0595EF5A5824EA8E7A1871FB63B8960EDBB97B08C2E7EA43229903AEBCB45B9FD9E24780B15BCADB5E026849592CC1FA9B399EBD8457CC4E7A686CF53E9146E1D867ACEB675728E8821DEDA4C2F807FD668A81601F551484C5D1334B62D5E90E33020111</pre>
<p>While other external libraries (as is the case in most of the web development frameworks), expect other data format codified as Base64. This is, something like this:</p>
<pre>-----BEGIN PUBLIC KEY-----

MIGHAoGBALS1MdNALCUNhkDnOWAfAfvoq7OWNb4XeKf05VxJQZwFle9aWCTqjnoYcftjuJYO27l7
CMLn6kMimQOuvLRbn9niR4CxW8rbXgJoSVkswfqbOZ69hFfMTnpobPU+kUbh2Ges62dXKOiCHe2k
wvgH/WaKgWAfVRSExdEzS2LV6Q4zAgER

-----END PUBLIC KEY-----</pre>
<p>So the first step to encode our Xojo keys (Public or Private ones) as Base64 is converting them previously from his hexadecimal form to the DER encoding (<em>Distinguished Encoding Rules</em>). Here is where we have to employ the <a href="http://developer.xojo.com/xojo-crypto$DEREncodePrivateKey"><b>DEREncodePrivateKey</b></a> and <a href="http://developer.xojo.com/xojo-crypto$DEREncodePublicKey"><b>DEREncodePublicKey</b></a> methods if we want to encode the Private or the Public key, respectively. Once we have done this, we will be able to encode the resulting chunk of data as Base64 without forgetting to add the header <code>“—–BEGIN PUBLIC KEY—–“</code> and the footer <code>“—–END PUBLIC KEY—–“</code> with the accompanying ends of lines, or maybe the header <code>“—–BEGIN CERTIFICATE—–”</code> and the footer <code>“—–END CERTIFICATE—–“</code> if we are dealing with a Public Key (for the Private keys we have to use the header <code>“—–BEGIN RSA PRIVATE KEY—–”</code> and the footer <code>“—–END RSA PRIVATE KEY—–“</code>).</p>
<p>You can interchange and use the Private and Public keys generated with Xojo using the <a href="http://phpseclib.sourceforge.net/">PHPSecLib</a> library.</p>
<p>In addition, as pointed by <a href="https://thezaz.com/">Thom McGrath</a>, you can use also these keys with OpenSSL this way:</p>
<pre>if (@openssl_public_encrypt($data, $result, $public_key, OPENSSL_PKCS1_OAEP_PADDING)) {
         return $result;
 } else {
         throw new \Exception('Unable to encrypt');
 }</pre>
<p>Xojo&#8217;s Crypto library will be able to use a private key to decrypt $result in this case.</p>
<p>Finally, if you are interested in the cryptography topic, let me recommend you some good books: <a href="https://www.schneier.com/books/applied_cryptography/" target="_blank" rel="noopener noreferrer">Applied Cryptography</a> and <a href="http://eu.wiley.com/WileyCDA/WileyTitle/productCd-0470474246.html" target="_blank" rel="noopener noreferrer">Cryptography Engineering</a>.</p>
<p><em>Javier Rodri­guez has been the Xojo Spanish Evangelist since 2008, he’s also a Developer, Consultant and Trainer who has be using Xojo since 1998. He manages <a href="http://www.aprendexojo.com/">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers and the Snippery app, among others.</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>If Smartphone Encryption Is A Red Herring, How Do We Track The Bad Guys?</title>
		<link>https://blog.xojo.com/2016/02/04/if-smartphone-encryption-is-a-red-herring-how-do-we-track-the-bad-guys/</link>
		
		<dc:creator><![CDATA[Geoff Perlman]]></dc:creator>
		<pubDate>Thu, 04 Feb 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Mobile]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/02/04/if-smartphone-encryption-is-a-red-herring-how-do-we-track-the-bad-guys/</guid>

					<description><![CDATA[Smartphone Encryption is a Red Herring, but the Good Guys have other options. We don't need universal back doors.]]></description>
										<content:encoded><![CDATA[<p>In the blog post <a href="http://blog.xojo.com/2016/01/27/smartphone-encryption-is-a-red-herring/">Smartphone Encryption is a Red Herring</a>, I pointed out the folly of requiring an encryption back door for the Good Guys to use. So the question arises- &#8220;What <em>can</em> be done? If we don&#8217;t want a global encryption back door that can be used by anyone, can we still track the Bad Guys?&#8221;</p>
<p>The answer is yes. There are plenty of options that don&#8217;t require a global back door. I&#8217;m not passing judgment on whether these are inherently good or bad options, just that they are available when there is a reason to track a Bad Guy.<br />
<span id="more-285"></span></p>
<p><strong>Keyloggers</strong><br />
A <a href="https://en.wikipedia.org/wiki/Keystroke_logging" target="_blank" rel="noopener">keylogger</a> is used to track everything someone types. They come in both software and hardware varieties. Once installed, they can provide regular data about passwords and other communications the Bad Guy is making. Some store the data for later retrieval, while others broadcast it on a regular basis. They exist in varieties for both computers and cell phones.</p>
<p><img fetchpriority="high" decoding="async" style="display: block; margin-left: auto; margin-right: auto;" title="keyboard.png" src="https://blog.xojo.com/wp-content/uploads/2016/02/keyboard.pngt1466486449161ampwidth424ampheight322" sizes="(max-width: 424px) 100vw, 424px" alt="keyboard.png" width="424" height="322" /><br />
<strong>Online Man in the Middle</strong><br />
With proper authorization, the Good Guys <a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack" target="_blank" rel="noopener">can stand between</a> the Bad Guys and common online services they might be using. Working with their internet provider, they can gather data similar to keyloggers by intercepting and relaying data back and forth.</p>
<p><strong>Digital Evidence Collection</strong><br />
When a warrant is served and computers or mobile devices are retrieved for analysis, gathering evidence quickly is paramount. The Bad Guys may have countermeasures installed on their devices, so being able to copy data from hard drives and other storage mediums across platforms while they are still online is important. Once images of the data are created, the evidence can be safely analyzed without being concerned about time bombs or other countermeasures. Xojo has been used to create tools that are used for both digital evidence collection and analysis. Being a cross platform tool is a particular advantage in this scenario.</p>
<p>None of the above options require a global back door, and they can all be limited to just the Bad Guys in question when surveillance is warranted. A <a href="https://www.onthewire.io/harvard-study-questions-going-dark-crypto-problem/" target="_blank" rel="noopener">recently released Harvard study</a> has similar findings. Some options are better than others depending on the region in the world and the technical prowess of the Bad Guys. <a href="../../../com/xojo/blog/smartphone-encryption-is-a-red-herring.html" target="_blank" rel="noopener">Smartphone Encryption is a Red Herring</a>, but the Good Guys have other options. We don&#8217;t need universal back doors.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Smartphone Encryption is a Red Herring</title>
		<link>https://blog.xojo.com/2016/01/27/smartphone-encryption-is-a-red-herring/</link>
		
		<dc:creator><![CDATA[Geoff Perlman]]></dc:creator>
		<pubDate>Wed, 27 Jan 2016 00:00:00 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Mobile]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2016/01/27/smartphone-encryption-is-a-red-herring/</guid>

					<description><![CDATA[Encryption Red Herring: Proposed AES encryption backdoor will not work but will create an exponentially greater problem for everyone but the bad guys.]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" style="width: 320px; margin: 0px 10px 10px 0px; float: left;" title="EnigmaMachine.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/EnigmaMachine.pngt1466486449161ampwidth320" sizes="(max-width: 320px) 100vw, 320px" alt="EnigmaMachine.png" width="320" data-constrained="true" />As the Founder and CEO of a <a href="https://xojo.com/" target="_blank" rel="noopener">software company</a> that makes a development tool for mobile platforms, as well as for desktop and web, I have a lot of experience with encryption. The current controversy over encryption is really important to me. During World War II, the Germans created a way of sending encrypted messages to commanders in the field. The device came to be known as an <a href="https://en.wikipedia.org/wiki/Enigma_machine" target="_blank" rel="noopener">Engima machine</a>. It looked like a typewriter but had an encryption key that changed a message into unreadable noise. That message could only be decoded if you knew the key used to encrypt it. The Allies worked very hard to get their hands on one of these devices so they could learn how it works and be able to decrypt the messages and know what the German military plans. Ultimately the Allies figured it out and it helped them win the war. If this has peaked your curiosity, check out the movie <a href="http://www.imdb.com/title/tt0141926/?ref_=nv_sr_1" target="_blank" rel="noopener">U-571</a> (a fictional account of the effort to obtain an Enigma machine) and <a href="http://www.imdb.com/title/tt2084970/" target="_blank" rel="noopener">The Imitation Game</a> about the team that figured out the encryption key.</p>
<p><span id="more-319"></span></p>
<p>Today, terrorists are using encryption to hide their communications just like the Nazis did in WWII. What makes encryption different today is that it is also being used by millions of ordinary people, many of whom have no idea they are even using it. Almost every smartphone in use today, encrypts text messages and other data automatically. This is all done behind the scenes without the user ever being aware of it.</p>
<p style="text-align: left;">The type of encryption used on the iPhone and Android is called <a href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard" target="_blank" rel="noopener">AES</a> and it&#8217;s formidable. Intercepting your text messages isn&#8217;t actually difficult but decrypting those messages is, at best, impractical. To decrypt a message, just like with the Enigma machine, you need to know the key that was used to encrypt it. If you don&#8217;t have that key, you&#8217;d have to guess at what the key might be then look at the results of decrypting the message with that key to see if you have anything but unintelligible gibberish. Even with access to the fastest computers in the world, it could literally take years to guess the right key. It will come as no surprise that governments at almost every level don&#8217;t like this one bit. At their most transparent, they are used to getting a search warrant and being able to look at whatever you&#8217;ve got to see if it supports their suspicion that you are in fact up to no good. At their least, they wish to get on your phone (ideally from a secure, remote location) and take your data without a warrant or you having any idea they were ever there. The problem for governments is that they can&#8217;t. In Apple&#8217;s case, even if Apple was willing to compile with a request that they decrypt the data on your phone, they can&#8217;t. The key is stored on your phone in a way that even Apple can&#8217;t get to it. In this sense, Apple is in complete alignment with you in terms of your privacy.</p>
<p><img decoding="async" style="display: block; margin-left: auto; margin-right: auto;" title="red_herring.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/red_herring.pngt1466486449161ampwidth321ampheight225" sizes="(max-width: 321px) 100vw, 321px" alt="red_herring.png" width="321" height="225" /></p>
<p>There are lawmakers here in the United States that want to force companies like Apple and Google to provide a <em>back door</em>. This would be a way for Apple to get into your data should a search warrant (presumably) be issued. Apple&#8217;s CEO Tim Cook as <a href="http://www.theguardian.com/technology/2016/jan/13/apple-tim-cook-us-government-encryption" target="_blank" rel="noopener">pointed out</a> what a <a href="http://techcrunch.com/2015/06/02/apples-tim-cook-delivers-blistering-speech-on-encryption-privacy/" target="_blank" rel="noopener">bad idea</a> this is. <strong>Back doors don&#8217;t get used by just the good guys.</strong> They will get used by the bad guys as well. In an effort to make it possible for law enforcement to get at the data of the tiny percentage of the population that is doing wrong, we would be opening everyone up to being hacked remotely. It&#8217;s not possible to make a back door that only the good guys can use. Think about your contacts, text messages, email, photos, all being exposed. Just the increased level of extortion alone would be so bad that your smartphone would go back to being useful as nothing more than a phone. Do any of you really want to go back to the 1980s?</p>
<p>What is worse than that, however, is <strong>what is not being talked about in the news</strong>. Smartphone encryption is a <a href="https://en.wikipedia.org/wiki/Red_herring" target="_blank" rel="noopener">red herring</a>. A back door wouldn&#8217;t solve the problem. Bad guys would simply write their own apps to encrypt the data themselves before they send it. This is incredibly easy to do. <a href="http://www.xojo.com" target="_blank" rel="noopener">Xojo</a>, the development tool my company created, has this same type of AES encryption built-in. Many other development tools have it as well. I could write an app to encrypt a message in a few minutes. Even if you have never written a line of code in your life, after a few hours learning Xojo, you could write the same app yourself. <strong>If you or I can do it, the bad guys can too.</strong> The smartest of them are almost certainly <em>already</em> doing this today. The end result would be that every law-abiding citizen&#8217;s personal and private data would become hackable- causing a digital tsunami of cybercrime that would be impossible for law enforcement to stop while achieving next to nothing towards actual security.</p>
<p><img decoding="async" style="width: 320px; margin: 10px auto; display: block;" title="edited_lock_and_code.png" src="https://blog.xojo.com/wp-content/uploads/2016/01/edited_lock_and_code.pngt1466486449161ampwidth320" sizes="(max-width: 320px) 100vw, 320px" alt="edited_lock_and_code.png" width="320" data-constrained="true" />I understand why our lawmakers and law enforcement are concerned about encryption. It is a barrier to evidence for them. Tim Cook has argued that we have to balance law enforcement with our personal privacy. That&#8217;s certainly true. However, in this case, you don&#8217;t even have to go that far. <strong>What our elected officials are proposing will not work and will only create an exponentially greater problem.</strong> You may be asking yourself, &#8220;Surely they have thought of this, right?&#8221; Clearly they haven&#8217;t. Too often people make decisions without complete information or having taken sufficient time to to think the matter through. We have all seen this many times in our lives. Smartphone encryption is just the latest example. It&#8217;s not the first and won&#8217;t be the last. I&#8217;m all for looking for better ways to catch the bad guys but smartphone back doors <strong>will not work</strong>. Your elected officials are wasting your precious taxpayer dollars. If you want to stop this, contact them and ask them to better educate themselves on this topic. You can point them to this blog post to start. I can&#8217;t speak for countries outside the United States, but here elected officials give considerable weight to their constituents that reach out to them. You can contact your Representatives in the House <a href="http://www.house.gov/representatives/" target="_blank" rel="noopener">here</a> and your Senators <a href="http://www.senate.gov/senators/contact/" target="_blank" rel="noopener">here</a>.</p>
<p>Lastly, while I am proud of Tim Cook for fighting back on this issue, it saddens me that he appears alone on the world stage while doing this. Powerful people in technology such as Mark Zukerberg of Facebook, Larry Page and Sergey Brin of Google, Satya Nadella of Microsoft and others should be taking an equal stand. They are in an even better position than we are as individuals to make it clear that the proposed solution won&#8217;t work. Until then, contact your elected officials and tell them that dog won&#8217;t hunt.</p>
<p style="text-align: center;"><span id="hs-cta-wrapper-2f9a74a4-35c0-4f3d-b3d0-101223008c8b" class="hs-cta-wrapper"><span id="hs-cta-2f9a74a4-35c0-4f3d-b3d0-101223008c8b" class="hs-cta-node hs-cta-2f9a74a4-35c0-4f3d-b3d0-101223008c8b"> <!-- [if lte IE 8]></p>





<div id="hs-cta-ie-element"></div>


<![endif]--> <a href="http://blog.xojo.com/2016/02/04/if-smartphone-encryption-is-a-red-herring-how-do-we-track-the-bad-guys/" target="_blank" rel="noopener"><img decoding="async" id="hs-cta-img-2f9a74a4-35c0-4f3d-b3d0-101223008c8b" class="hs-cta-img aligncenter" style="border-width: 0px;" src="https://blog.xojo.com/wp-content/uploads/2013/08/2f9a74a4-35c0-4f3d-b3d0-101223008c8b.png" alt="Security: How to Track The Bad Guys" width="384" height="64" /></a></span></span><br />
<!-- end HubSpot Call-to-Action Code --></p>
]]></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>
