Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

nodejs中反解php的tripledes-ecb加密的密文。

<?php
function _encrypt($value,$mAuthkey) {
    if(null==$value) return false;
    $td = mcrypt_module_open('tripledes', '', 'ecb', '');
    $td_size = mcrypt_enc_get_iv_size($td);
    $iv = mcrypt_create_iv($td_size,MCRYPT_RAND);
    $key = substr($mAuthkey, 0, $td_size);
    mcrypt_generic_init($td, $key, $iv);
    $ret = base64_encode(mcrypt_generic($td, $value));
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    return $ret;
}

以上为php的加密代码,请问在nodejs中需要怎么写才可以反解出来以上代码加密出来的内容哪?

已经琢磨一天了,网上的方法都尝试过了,可是解出来的都是乱码,到底怎么样才可以呀。。。

真心求帮助啊~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
// php的padding算法为PKCS7,而node的padding算法是:ZeroPadding;详情见https://ostack.cn/a/1190000019793040
// 另外,chiper和chiperiv是两回事儿,千万不要混用。
function decodeCookie(value) {
    if (!value) {
        return '';
    }
    const PKCS7 = 'x01x08x08x08x08x08x08x08x08x08x08x08x08x08x08x08x08';
    var key = COOKIE_KEY + PKCS7;
    value = Buffer.from(decodeURIComponent(value), 'base64');
    const cipher = crypto.createDecipheriv('des-ede3', key, null);
    cipher.setAutoPadding();
    let text = cipher.update(value) + cipher.final();
    console.log(text);
}

终于弄出来了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...