[erlang-questions] 3des decryption in erlang

Xiaobin Xu xuxb1979@REDACTED
Mon Aug 10 14:59:14 CEST 2015


Hi, all,

   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:

public  function decrypt($value) {
$td = mcrypt_module_open ( MCRYPT_3DES, '', MCRYPT_MODE_ECB, '' );
mcrypt_generic_init ( $td, $this->key,$this->iv );
$ret = trim ( mdecrypt_generic ( $td, base64_decode ( $value ) ) );
$ret = $this->UnPaddingPKCS7 ( $ret );
mcrypt_generic_deinit ( $td );
mcrypt_module_close ( $td );
return $ret;
}


private  function UnPaddingPKCS7($data) {
$padlen = ord (substr($data, (strlen( $data )-1), 1 ) );
if ($padlen > 8 )
return $data;

for($i = -1*($padlen-strlen($data)); $i < strlen ( $data ); $i ++) {
if (ord ( substr ( $data, $i, 1 ) ) != $padlen)return false;
}

return substr ( $data, 0, -1*($padlen-strlen ( $data ) ) );
}

   I googled and read crypto module document for a couple hours, and got no
idea how to translate these two functions into erlang.

   Any ideas?


   Thanks,
    Xiaobin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150810/aed21965/attachment.htm>


More information about the erlang-questions mailing list