<div dir="ltr"><div>Hi!<br><br></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-08-11 6:22 GMT+02:00 Alex Xu <span dir="ltr"><<a href="mailto:xuxb1979@gmail.com" target="_blank">xuxb1979@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Thank you for your rapid answer, Sean.</div><div><br></div><div>I’ve tried block_decrypt yesterday, but I couldn’t find the counterpart of ECB mode decryption.</div><div><br></div><div>I tried des_ede3, des3_cbc, de3_cbf. For des_ede3/des3_cbc, the output seams the same, and only the first 8 bytes output result are correct.</div><div><br></div><div>For des3_cbf, the output are completely incorrect.</div><div><br></div><div>So I’m still confused how to do DES3 ECB decryption with block_decrypt? </div><div><div class="h5"></div></div></div></blockquote><div><br><br></div><div>It actually looks like this algorithm was missed when making the new crypto-API. I think it could probably be added quite easily to the new API but this will probably not be highly prioritized<br></div><div>by Ericsson.<br><br></div><div>Regards Ingela Erlang/OTP Team - Ericsson AB<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="h5">
<div><blockquote type="cite"><div>On Aug 10, 2015, at 21:54, Sean Cribbs <<a href="mailto:seancribbs@gmail.com" target="_blank">seancribbs@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div>Xiaobin,</div><div><br></div>Here's what I came up with:<div><br></div><div>    crypto:start(),</div><div><div>    %% To decrypt the text, note Key and IV must be defined in this scope</div><div>    Unencoded = base64:decode(Value),</div><div>    Cleartext = crypto:block_decrypt(des3_cbc, Key, IV, Unencoded),</div><div>    %% To unpad the text, see <a href="https://github.com/camshaft/pkcs7.erl" target="_blank">https://github.com/camshaft/pkcs7.erl</a></div><div>    pkcs7:unpad(Cleartext)</div></div><div><br></div><div>The main thing to note is the difference in how you use the crypto module. In Erlang, you don't need to initialize, decrypt, and cleanup in separate steps. You do however, need to make sure the crypto application is started before you try this. Generally, you would make crypto a dependency (see <a href="http://erlang.org/doc/man/app.html" target="_blank">http://erlang.org/doc/man/app.html</a>) of the application that contains this code and it would be started automatically when your release is booted.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 10, 2015 at 7:59 AM, Xiaobin Xu <span dir="ltr"><<a href="mailto:xuxb1979@gmail.com" target="_blank">xuxb1979@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi, all,<div><br></div><div>   For some reason i have to decrypt a message that is encrypted using 3DES algorithm, and I've PHP function example how to decrypt the message:</div><div><br></div><div><div><span style="white-space:pre-wrap">   </span>public  function decrypt($value) {</div><div><span style="white-space:pre-wrap">              </span>$td = mcrypt_module_open ( MCRYPT_3DES, '', MCRYPT_MODE_ECB, '' );</div><div><span style="white-space:pre-wrap">               </span>mcrypt_generic_init ( $td, $this->key,$this->iv );</div><div><span style="white-space:pre-wrap">         </span>$ret = trim ( mdecrypt_generic ( $td, base64_decode ( $value ) ) );</div><div><span style="white-space:pre-wrap">              </span>$ret = $this->UnPaddingPKCS7 ( $ret );</div><div><span style="white-space:pre-wrap">                </span>mcrypt_generic_deinit ( $td );</div><div><span style="white-space:pre-wrap">           </span>mcrypt_module_close ( $td );</div><div><span style="white-space:pre-wrap">             </span>return $ret;</div><div><span style="white-space:pre-wrap">     </span>}</div><div><span style="white-space:pre-wrap">        </span> </div><div><span style="white-space:pre-wrap">       </span> </div><div><span style="white-space:pre-wrap">       </span>private  function UnPaddingPKCS7($data) {</div><div><span style="white-space:pre-wrap">               </span>$padlen = ord (substr($data, (strlen( $data )-1), 1 ) );</div><div><span style="white-space:pre-wrap">         </span>if ($padlen > 8 )</div><div><span style="white-space:pre-wrap">                     </span>return $data;</div><div><span style="white-space:pre-wrap">    </span> </div><div><span style="white-space:pre-wrap">               </span>for($i = -1*($padlen-strlen($data)); $i < strlen ( $data ); $i ++) {</div><div><span style="white-space:pre-wrap">                  </span>if (ord ( substr ( $data, $i, 1 ) ) != $padlen)return false;</div><div><span style="white-space:pre-wrap">             </span>}</div><div><span style="white-space:pre-wrap">        </span> </div><div><span style="white-space:pre-wrap">               </span>return substr ( $data, 0, -1*($padlen-strlen ( $data ) ) );</div><div><span style="white-space:pre-wrap">      </span>}</div></div><div><br></div><div>   I googled and read crypto module document for a couple hours, and got no idea how to translate these two functions into erlang.</div><div><br></div><div>   Any ideas?</div><div><br></div><div><br></div><div>   Thanks, </div><span><font color="#888888"><div>    Xiaobin</div><div><br></div></font></span></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div></div></div>