<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="115147" data-post-id="115147">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wyrdforge" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wyrdforge/120/9048_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wyrdforge
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Normally, you can assume, that the Database is isolated efficiently. So the focus in ISP settings is set on protecting the communication between BRAS, Radius and customer modem. So they do a challenge handshake and the customer sends some calculated hash from this one time challenge and his dialin password.</p>
<p>The radius now takes this challenge and has to calculate with the same plaintext password. Of course, you can deploy a kind of “middleware” that can handle stronger encryption, but you must be prepared for a lot of queries, when several thousand FritzBoxes want do dialin between 4 and 5 a.m <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="115147" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/encrypt-string-with-my-key/18828/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-115147" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="115147"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="115173" data-post-id="115173">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wyrdforge" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wyrdforge/120/9048_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wyrdforge
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I found some interesting reference on stackoverflow. Though from 2013, this seems still valid:</p>
<blockquote>
<p>MySQL’s implementation of AES gives headaches to a lot of people. It’a mainly because of how MySQL processes the encryption key. The encryption key gets broken into 16-byte blocks and MySQL will XOR the bytes from one block with the bytes in the preceding block. If the user provided key happens to be less than 16 bytes in length then the key is essentially padded with null bytes to get up to 16 bytes. That’s how the key is processed by MySQL’s aes_encrypt().</p>
</blockquote>
<p>So it seems, one will have to implement two methods:</p>
<ul>
<li>PKCS7 padding for the data to be encrypted though some say this might also be PKCS5</li>
<li>The key padding algorithm as stated in the text</li>
</ul>
<p>But you brought up another thing for me to check, before trying to implement this. There is also an asymmetric encryption method with 1024 bit public/private rsa key available in MySQL 5.7, that is used in Percona Cluster.</p>
<p>If this works out (regarding server load and authentication speed), I think this would be a way better method, regarding application security. The elixir microservice configuring the radius would yield the private key, the radius in plaintext configuration would use only the public key in plaintext files.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="115173" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/encrypt-string-with-my-key/18828/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-115173" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="115173"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="115176" data-post-id="115176">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="voltone" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/voltone/120/24672_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  voltone
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="wyrdforge" data-post="13" data-topic="18828">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wyrdforge/48/9048_2.png" class="avatar"> wyrdforge:</div>
<blockquote>
<p>The elixir microservice configuring the radius would yield the private key, the radius in plaintext configuration would use only the public key in plaintext files.</p>
</blockquote>
</aside>
<p>This approach does not really offer any benefits over symmetrical crypto, and will have significant performance impact.</p>
<p>The fact that the key stored in the Radius configuration files is notionally the “public” half of the key pair does not change the fact that anyone who has access to the plaintext config file will be able to decrypt all passwords. The fact that the “private” half is kept more secure just means someone with only the public key can’t encrypt new passwords, which presumably isn’t what you are concerned about.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="115176" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/encrypt-string-with-my-key/18828/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-115176" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="115176"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="115182" data-post-id="115182">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wyrdforge" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wyrdforge/120/9048_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wyrdforge
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My main concern, in respect to GDPR is, that the database could be leaked due to someone here deploying an insecure script somewhere. In law terms, any encryption would do to avoid potentially high fines in this case. If I could implement something, that works and is not too easy to reverse engineer, I’d feel a lot more comfortable.</p>
<p>That is, why i thought about rsa. But I fear, you are completely right with the performance impact.</p>
<p>The radius itself is placed in a private management network with the BRAS and if this system is compromised, our problems are far worse than some DB leakage, I assume. So I would deem this  a secondary or tertiary risk and would require a directed attack at our internal management network.</p>
<p>Would a customer have direct access to the radius for authorization, I would completely agree, that it makes no real difference, as the risk of exploting the service is clearly there.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="115182" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/encrypt-string-with-my-key/18828/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-115182" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="115182"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="115185" data-post-id="115185">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="muelthe" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/muelthe/120/35411_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  muelthe
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I have been tinkering with a requirement to encrypt some data before storing in a database. Now I am <em>extremely</em> new to a lot of this and in all fairness my need is very small, but I found a lot of good references with the following that certainly helped: <a href="https://github.com/dwyl/phoenix-ecto-encryption-example" class="inline-onebox" rel="noopener nofollow ugc">GitHub - dwyl/phoenix-ecto-encryption-example: 🔐 A detailed example for how to encrypt data in an Elixir (Phoenix v1.7) App before inserting into a database using Ecto Types · GitHub</a>.</p>
<p>Most likely it doesn’t fit your requirements, but just in case <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="115185" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/encrypt-string-with-my-key/18828/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-115185" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="115185"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="115418" data-post-id="115418">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wyrdforge" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wyrdforge/120/9048_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wyrdforge
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for all the input <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p>
<p>Though we decided against aes just now, I came up with the following solution to the mysql implementation of aes_ecb as a personal challenge, which works well in my test cases:</p>
<pre><code>#
# Encrypt password with 128-bit aes and insert into database as hex value
#
@aes_blocksize 16

def encrypt(data, key) do
  :crypto.block_encrypt(
    :aes_ecb,
    mysql_key_pad(key),
    pkcs7_pad(data, @aes_block_size)
  )
  |&gt; Base.encode16()
end

# PKCS7 Padding
defp pkcs7_pad(data, blocksize) do
  pad = blocksize - rem(byte_size(data), blocksize)
  data &lt;&gt; to_string(List.duplicate(pad, pad))
end

defp mysql_key_pad(key) when byte_size(key) &lt; @aes_block_size do
  bits = 8 * (@aes_block_size - byte_size(key))
  key &lt;&gt; &lt;&lt;0 :: size(bits)&gt;&gt;
end

defp mysql_key_pad(key) when byte_size(key) == @aes_block_size do
  key |&gt; :binary.bin_to_list()
end

defp mysql_key_pad (key) do
  bytelist = :binary.bin_to_list(key)
  bytes_to_pad = (@aes_block_size - rem(length(bytelist), @aes_block_size))

  bytelist ++ List.duplicate(&lt;&lt;0::8&gt;&gt;, bytes_to_pad)
  |&gt; Enum.chunk_every(@aes_block_size)
  |&gt; Enum.reduce(
      List.duplicate(&lt;&lt;0::8&gt;&gt;, @aes_block_size),
        fn chunk, acc -&gt;
          :crypto.exor(acc, chunk)
        end
    )
end
</code></pre>
<p>You can also implement the functionality of :crypto.exor(acc, chunk) in Elixir with a recursive function like<br>
do_xor_calculation(chunk1, chunk2, accumulator), as I did first, but with :crypto.exor/2 it is way more comfortable.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="115418" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/encrypt-string-with-my-key/18828/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-115418" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="115418"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="122164" data-post-id="122164">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="IkechukwuAKalu" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/IkechukwuAKalu/120/18249_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  IkechukwuAKalu
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Did you try <code>encrypted |&gt; :base64.encode</code> ?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="122164" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/encrypt-string-with-my-key/18828/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-122164" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="122164"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>