<?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"><channel><title><![CDATA[Encrypt und Decrypt mit PHP]]></title><description><![CDATA[<p dir="auto">Es existiert ja Code in Python und Javascript zur Ver- und Entschlüsselung (<a href="https://air-q-updates.s3.eu-central-1.amazonaws.com/dokumentation/index.html" rel="nofollow ugc">https://air-q-updates.s3.eu-central-1.amazonaws.com/dokumentation/index.html</a>). Das lässt sich auch auf PHP portieren.<br />
Hierzu nutzt man in PHP OpenSSL.</p>
<p dir="auto">PHP-decrypt:</p>
<pre><code>function decrypt($msgb64,$password)
{
    $airqpass = $password;
	if (strlen($airqpass) &lt; 32) {
		for ($i = strlen($airqpass); $i &lt; 32; $i++) {
			$airqpass = $airqpass . '0';
		}
	} else {
		if (strlen($airqpass) &gt; 32) {
			$airqpass = substr($airqpass,0,32);
		}
	}

	$key = utf8_encode ($airqpass);
//	$cyphertext = base64_decode ($msgb64);
//	But with verly long messages there could be some problems in base64_decode
	$decoded = "";
	for ($i=0; $i &lt; ceil(strlen($msgb64)/256); $i++)
	   $decoded = $decoded . base64_decode(substr($msgb64,$i*256,256));
	$cyphertext = $decoded;

	$iv = substr($cyphertext,0,16);
	$cyphertext = substr($cyphertext,16,strlen($cyphertext));

	$decrypted = openssl_decrypt($cyphertext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
	
	return utf8_encode($decrypted);
}
</code></pre>
<p dir="auto">PHP-encrypt:</p>
<pre><code>function encrypt($msgb64,$password)
{
    $airqpass = $password;
	if (strlen($airqpass) &lt; 32) {
		for ($i = strlen($airqpass); $i &lt; 32; $i++) {
			$airqpass = $airqpass . '0';
		}
	} else {
		if (strlen($airqpass) &gt; 32) {
			$airqpass = substr($airqpass,0,32);
		}
	}

	$key = utf8_encode ($airqpass);
	
	$iv = substr(openssl_random_pseudo_bytes(32),0,16);

	$encrypted = openssl_encrypt($msgb64, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
	return base64_encode($iv . $encrypted);
}
</code></pre>
]]></description><link>https://forum.air-q.com/topic/68/encrypt-und-decrypt-mit-php</link><generator>RSS for Node</generator><lastBuildDate>Mon, 17 Aug 2026 13:53:54 GMT</lastBuildDate><atom:link href="https://forum.air-q.com/topic/68.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 Jul 2020 09:29:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Encrypt und Decrypt mit PHP on Thu, 23 Jul 2020 10:35:20 GMT]]></title><description><![CDATA[<p dir="auto">&lt;klugscheissermodus&gt; ;-) Ja, so ähnlich mache ich es auch. Aber kleiner Tip, mit str_pad(..,32,"0",STR_PAD_RIGHT) kannst Du Dir die eine Schleife sparen und substr braucht den strlen als dritten Parameter nicht für den String nach dem 16ten Zeichen.</p>
<p dir="auto">Die openssl_random_pseudo_bytes Länger kann man natürlich auch hart kodiert angeben, aber etwas besser lesbar ist es evtl.  mit openssl_cipher_iv_length('AES-256-CBC').</p>
<p dir="auto">Wie ich bei Dir sehe hast du das Padding und Unpadding von den Beispielen nicht mit eingebaut..?<br />
&lt;/klugscheiserfragenmodus&gt;</p>
]]></description><link>https://forum.air-q.com/post/221</link><guid isPermaLink="true">https://forum.air-q.com/post/221</guid><dc:creator><![CDATA[tuxbox]]></dc:creator><pubDate>Thu, 23 Jul 2020 10:35:20 GMT</pubDate></item></channel></rss>