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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="CharlesO" data-post="11" data-topic="66623">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/charleso/48/34571_2.png" class="avatar"> CharlesO:</div>
<blockquote>
<p>The steps, and specifications are clearly spelt out by Meta.</p>
</blockquote>
</aside>
<p>Those are not specifications, those are just words on a web page, specifications should follow conventions and adhere to strict rules. You want a specification, read a ISO standard and you will see how one should look like.</p>
<aside class="quote no-group" data-username="CharlesO" data-post="11" data-topic="66623">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/charleso/48/34571_2.png" class="avatar"> CharlesO:</div>
<blockquote>
<p>Its funny how this is a breeze in JavaScript, and nodejs.</p>
<p>There is a python reference done by meta themselves.</p>
</blockquote>
</aside>
<p>You should use the right tools for the job, if those ecosystems work much better, then use them. I don’t find this even close as an argument to blame elixir/erlang ecosystem that they lack some certificate format used by a company, especially when those are homebrewed and not industry standard.</p>
<aside class="quote no-group" data-username="CharlesO" data-post="11" data-topic="66623">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/charleso/48/34571_2.png" class="avatar"> CharlesO:</div>
<blockquote>
<p>WhatsApp is high traffic solution. Wouldn’t want this to become an avoidable bottleneck.</p>
</blockquote>
</aside>
<p>Thinking about what ifs will get you nowhere. You can always start with <code>System.cmd/1</code>, then  if that becomes a bottleneck, you can refactor to NIFs that would be implemented in C/rust and use the dev library for openssl.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342230" data-batch-url="/posts/batch_likers">
                        1
                      </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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-342230" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342230"
                     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="342231" data-post-id="342231">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="CharlesO" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/CharlesO/120/34571_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  CharlesO
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>All your points are well taken sir.</p>
<p>it’s just the frustration of loosing time and sleep on parts of a project that you expected would be straight forward.</p>
<p>Forgive my rant please <img src="https://forum.elixirforum.com/images/emoji/apple/folded_hands.png?v=15" title=":folded_hands:" class="emoji" alt=":folded_hands:" 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="342231" 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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-342231" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342231"
                     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="342233" data-post-id="342233">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Cryptography stuff from scratch is very hard, even if you know the theory, you might still fail to implement it correctly.</p>
<p>If there isn’t a ready solution available, I would always consider first using <code>Ports</code> or another mechanism to borrow the implementation from another ecosystem, as I’ve fallen myself into this trap of spending countless days debugging myself.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342233" data-batch-url="/posts/batch_likers">
                        3
                      </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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-342233" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342233"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="342236" data-post-id="342236">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="CharlesO" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/CharlesO/120/34571_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  CharlesO
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I have used the X509 library with some success:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"> def run do
    private_unencrypted_pem = File.read!("priv/flows/private_unencrypted.pem")
    [private_key] = X509.from_pem(private_unencrypted_pem)

    IO.inspect(private_key, label: "private_key")

    m = %{
      encrypted_aes_key:
        "i/j13zUEy37M00eFJYchyIyk+HIlmLs8X6gmJLO9UfiljUmQCX1kYVPYfVRbS+5moWKtkIc0K/KG59CObmT8sMbhSXFEbnCKL7bbLka80NC5lqoill4LKrAtOaWJ/Zxbw7YjWS1+zinkIZZCbJ0OGZjH24XVgx3pVx5PYK53JDSYt6T6kUo1Kt15uc5M7zne1/T46c5YCw2BnSGDvXX+74W7T8xo+dTl6krOzFGuxNXFOYtG3coFK3Ad4eteMIhlsxpoRjFggfIWv9VuA7TT9AOQ9mdF2juN98Hu0hm3kSi5IHHGagTq+UwrspnMl76kw+GZXinjQNSI2ZV8yYYHxQ==",
      encrypted_flow_data: "esYLI3l/ZREnkg3EDoipH/TeF8fL6goV1GELcV/Jv+WWVkB/5JcJ5NRoFzfnDZrTKA==",
      initial_vector: "65SPDGDmgHlG4MiRzy5abQ=="
    }

    {:ok, cipherText} = Base.decode64(m.encrypted_aes_key)

    :public_key.decrypt_private(cipherText, private_key)
  end
</code></pre>
<p>I now get the following:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">private_key: {:RSAPrivateKey, :"two-prime",
 20521716780355580191550654660427168801033017999979128058505635221350308656209136095559482889939248891214276985696478264628555013673442179387450639676235923276763753945178489184101412002814944057148911035896122839963913153231089553623783047356337013294406425764168745177227849841528233456796700583848965253978778841370892407240172397435296874412542326417557014040885255496065392387262072486147756337139772431797705036236225154549695224561441211981922041229894695275663304593054518352707833166848660424321605184883485794491793623948711036778133900858257107938104282992179043651995979330716543636145006439954526445240763,
 65537,
 6101372529490646200350405207110844013124316885569881291789100848192788259551627581701581154316893734002322154909377588023366868203106960424866498528944824527331762906782471912846422827942218669660596785547644132882140589143655949347077416997089074935403042647890931836646240355252416633438877441388789355230952210159381055825921275221081940869473469830689864917813711227959475309631843238750002918360166052964140819289834990306960827834019082104583666169035743860983433438292667142785107052016117789083159263948861977159066001010422854460585806501949831365120461251443129509716016262603213687243268156580468396104873,
 151190366275169636659156710850755871081855237513754653133885676881553005863138306361469825928422763931411709054490695520372670862263762193129823956501853620635206291633382027347117489353456935897153558861010747074354736527517171778666319726670165784090610050738948575379033685918723403262535625181590972124391,
 135734288407011498129478129421886631648677888079098386018899059790453014073190770088624655395583559931425640561364135203441528615363819617475833915933485975414483867477768271128867544676095890623937965185083854342062520563606869218948617789616908888635193647838433353329362488409479692935739217245906616276493,
 111084097790285920081964599247533404097433410085330638535527459499222429136546313195866381709651234094104652553394814695469503446293310299885366787516628096202548993007470762787713831077828682687943271225039130462552897954941588041661056006204461950280468363873565341740562278474119494543503905026839319616913,
 40289288682448001481800174735553361390691227196891845876766458795850931271888857447457396911825182589163724092348086151525825963267656179238558328374110848524313817752491358748033329975191012104726570284655022636314482086818811158829477422851484331150654165302059050953142323985376328893280665777875420089821,
 102567540933109511029738225524188193914715584345455927873497835038050930695268722174185678374967621653339377683257747663760985231626325445842500766475654732178732141643253908789737635412175714081538765312270435649325915057332637228855149308606011583122920805142192972378445966624673177556168108118988753484264,
 :asn1_NOVALUE}
** (ErlangError) Erlang error: {:error, {~c"pkey.c", 1179}, ~c"Couldn't get the result"}
    (crypto 5.4.2.1) crypto.erl:1607: :crypto.pkey_crypt(:rsa, &lt;&lt;139, 248, 245, 223, 53, 4, 203, 126, 204, 211, 71, 133, 37, 135, 33, 200, 140, 164, 248, 114, 37, 152, 187, 60, 95, 168, 38, 36, 179, 189, 81, 248, 165, 141, 73, 144, 9, 125, 100, 97, 83, 216, 125, 84, 91, 75, 238, 102, 161, 98, ...&gt;&gt;, [&lt;&lt;1, 0, 1&gt;&gt;, &lt;&lt;162, 144, 53, 31, 174, 226, 155, 127, 205, 227, 111, 224, 86, 190, 49, 167, 12, 2, 155, 192, 252, 33, 242, 162, 138, 61, 227, 59, 7, 48, 48, 20, 57, 0, 223, 186, 106, 138, 48, 116, 103, 75, 97, 158, 230, 71, 188, 103, ...&gt;&gt;, &lt;&lt;48, 85, 9, 198, 98, 187, 179, 25, 219, 127, 252, 122, 73, 176, 0, 153, 54, 227, 235, 165, 4, 17, 159, 207, 29, 164, 234, 211, 88, 254, 197, 188, 173, 122, 10, 10, 165, 180, 114, 85, 153, 132, 123, 0, 192, 92, 161, ...&gt;&gt;, &lt;&lt;215, 77, 94, 212, 206, 182, 111, 103, 65, 125, 200, 200, 28, 156, 156, 158, 211, 17, 140, 199, 66, 152, 42, 62, 176, 96, 177, 6, 205, 145, 161, 188, 29, 147, 72, 59, 180, 53, 91, 214, 148, 27, 207, 175, 10, 249, ...&gt;&gt;, &lt;&lt;193, 74, 195, 80, 188, 0, 232, 17, 152, 23, 243, 27, 74, 196, 70, 183, 8, 185, 130, 181, 190, 209, 161, 151, 220, 2, 222, 171, 94, 211, 211, 140, 248, 255, 100, 188, 191, 84, 120, 67, 246, 255, 134, 70, 135, ...&gt;&gt;, &lt;&lt;158, 48, 98, 180, 201, 12, 145, 221, 179, 232, 207, 84, 248, 112, 185, 66, 152, 162, 20, 101, 115, 48, 138, 25, 117, 78, 21, 195, 129, 214, 182, 150, 152, 196, 86, 22, 71, 217, 204, 152, 100, 73, 234, 214, ...&gt;&gt;, &lt;&lt;57, 95, 180, 187, 249, 34, 23, 192, 105, 49, 234, 178, 86, 46, 14, 131, 115, 238, 132, 178, 231, 210, 23, 178, 24, 215, 45, 59, 22, 233, 175, 104, 175, 220, 55, 13, 163, 137, 50, 45, 146, 90, 100, ...&gt;&gt;, &lt;&lt;146, 15, 159, 112, 112, 202, 238, 214, 204, 68, 134, 252, 132, 230, 56, 165, 213, 120, 240, 196, 0, 246, 98, 29, 202, 201, 7, 158, 79, 180, 183, 93, 110, 114, 198, 212, 240, 178, 71, 223, 222, 158, ...&gt;&gt;], [rsa_padding: :rsa_pkcs1_padding], true, false)
    iex:10: (file)
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342236" 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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-342236" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342236"
                     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="342246" data-post-id="342246">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Assuming this: <a href="https://developers.facebook.com/docs/whatsapp/flows/guides/implementingyourflowendpoint/#request-decryption-and-encryption" rel="noopener nofollow ugc">https://developers.facebook.com/docs/whatsapp/flows/guides/implementingyourflowendpoint/#request-decryption-and-encryption</a> is the original instructions, it says:</p>
<aside class="quote no-group">
<blockquote>
<p>decrypt resulting byte array with the private key corresponding to the <a href="https://developers.facebook.com/docs/whatsapp/flows/guides/implementingyourflowendpoint/#upload_public_key" rel="noopener nofollow ugc">uploaded</a> public key using RSA/ECB/OAEPWithSHA-256AndMGF1Padding algorithm with SHA256 as a hash function for MGF1;</p>
</blockquote>
</aside>
<p><code>using RSA/ECB/OAEPWithSHA-256AndMGF1Padding algorithm with SHA256 as a hash function for MGF1;</code> being the important part in this case.</p>
<p><code>private_decrypt</code> defaults to <code>RSA PCKS1</code> padding (which should no longer be used as it is not secure)</p>
<p>I’m not sure erlang crypto module supports <code>RSA/ECB/OAEPWIthSHA-256andMGF1Padding</code> mode.</p>
<p>You can try with:<br>
<code>:public_key.decrypt_private(cipher, key, [rsa_padding: :rsa_pkcs1_oaep_padding])</code> but I am pretty sure that uses SHA1 instead of SHA256.</p>
<p>In addition <code>public_key:decrypt_private2/3</code> and the equivalent in <code>crypto</code> module are deprecated. I have not found what they are replaced with though. It seems that the original intent was not for encrypt/decrypt but for signing and verification. The docs suggest that they have been replaced with <code>:public_key.sign/verify</code> which will not help you much.</p>
<ul>
<li><a href="https://www.erlang.org/doc/apps/public_key/public_key.html" class="inline-onebox" rel="nofollow">public_key — OTP 29.0.2 (public_key 1.21.2)</a></li>
<li><a href="https://www.erlang.org/doc/apps/crypto/crypto.html" class="inline-onebox" rel="nofollow">crypto — OTP 29.0.2 (crypto 5.9)</a></li>
</ul>
<p>Might give you additional options to try.</p>
<p>We used erlang for a crypto heavy application but we used a port (<a href="https://www.erlang.org/doc/system/c_port.html" class="inline-onebox" rel="nofollow">Ports — Erlang System Documentation v29.0.2</a>) to do all the asymmetric crypto operations rather than the built-in and it performed very well with stable latency compared to our java and golang equivalent apps.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342246" 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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-342246" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342246"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="342252" data-post-id="342252">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="CharlesO" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/CharlesO/120/34571_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  CharlesO
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for the explanations. The port you used was to connect to which external program?</p>
<p>Im going to see if these crypto csn be done in rust, then maybe an NIF might be the way foreword.</p>
<p>Also using openSsl via cmd was equally suggested.</p>
<p>Meta provides ready to use code in PHP, django java and nodejs</p>
<p>Interop via a port might indeed be the quickest solution.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342252" 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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-342252" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342252"
                     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="342253" data-post-id="342253">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="CharlesO" data-post="17" data-topic="66623">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/charleso/48/34571_2.png" class="avatar"> CharlesO:</div>
<blockquote>
<p>The port you used was to connect to which external program?</p>
</blockquote>
</aside>
<p>We wrote a custom C application which used openssl to do the crypto. We found a port worked better than a NIF in terms of predictable latency but this was a long way back when dirty NIFs were just experimental.</p>
<p>Unfortunately the port code doesn’t compile any longer as erlang has changed a bit since then but our port code was only around 200 lines of code.</p>
<p>It was just a slight enhancement of the code found here: <a href="https://www.erlang.org/doc/system/c_port.html" class="inline-onebox" rel="nofollow">Ports — Erlang System Documentation v29.0.2</a></p>
<p>openssl via cmd would probably be the fastest to just get something going. You can then revisit if needed.</p>
<aside class="quote no-group" data-username="CharlesO" data-post="17" data-topic="66623">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/charleso/48/34571_2.png" class="avatar"> CharlesO:</div>
<blockquote>
<p>Meta provides ready to use code in PHP, django java and nodejs</p>
</blockquote>
</aside>
<p>Can you link the 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="342253" data-batch-url="/posts/batch_likers">
                        1
                      </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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-342253" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342253"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="342254" data-post-id="342254">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="CharlesO" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/CharlesO/120/34571_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  CharlesO
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>here is the code from MEta: <a href="https://developers.facebook.com/docs/whatsapp/flows/guides/implementingyourflowendpoint#handling-decryption-errors" rel="noopener nofollow ugc">Implementing Endpoints for Flows - WhatsApp Flows (facebook.com)</a></p>
<p>here is the full WhatsApp flows endpoint example from meta on GitHub. it is done in <strong>nodejs</strong></p>
<p><a href="https://github.com/WhatsApp/WhatsApp-Flows-Tools/blob/main/examples/endpoint/nodejs/basic/src/encryption.js" rel="noopener nofollow ugc">WhatsApp-Flows-Tools/examples/endpoint/nodejs/basic/src/encryption.js at main · WhatsApp/WhatsApp-Flows-Tools (github.com)</a></p>
<p>The implementation we need is in <em>examples/endpoint/nodejs/basic/src/encryption.js</em></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342254" 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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-342254" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342254"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="342256" data-post-id="342256">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Here is the call to nodejs crypto module.</p>
<pre data-code-wrap="javascript"><code class="lang-javascript">    decryptedAesKey = crypto.privateDecrypt(
      {
        key: privateKey,
        padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
        oaepHash: "sha256",
      },
</code></pre>
<p>As you can see they are setting the OAEP has to <code>sha256</code>.</p>
<p>I’ve had a look at the OTP code and it looks like there is no way to do this with <code>decode_private</code> which uses an older openssl API which is deprecated and should not be used (and the older openssl library doesn’t support sha256 either).</p>
<p>To me it looks like erlang/OTP does not ship with any support to do what is required.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342256" data-batch-url="/posts/batch_likers">
                        1
                      </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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-342256" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342256"
                     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 #19"></div>
  </section>
</div>
    <div class="postbit" id="342257" data-post-id="342257">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="CharlesO" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/CharlesO/120/34571_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  CharlesO
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I will attempt this now with: <strong>elixir-node</strong>: An Elixir library for interacting with Node.js.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="342257" 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/need-help-with-basic-crypto-in-erlang-elixir-decryption-error-failed-to-decrypt/66623/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-342257" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="342257"
                     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 #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/66623/load_more?page=3">Load more posts (5 remaining)</a>
</div></template></turbo-stream>