JS加密算法练习

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS加密算法练习相关的知识,希望对你有一定的参考价值。

const crypto = require("crypto");
/**
 * 参数讲解:
 *      加密数据
 *          data
 *      加密方式
 *          md5 sha1 sha256 sha512
 * 加密形式
 *      1.使用加密算法加密
 *      2.获取密文中所有的数字
 *      3.在数字当中,从第二位开始,获取10位数字
 */
function cipher(encrypt_data,encrypt_type){
    return crypto.createHash(encrypt_type).update(encrypt_data,"utf-8").digest("hex").replace(/[^0-9]/ig,"").substring(1,11);
}
// const result = cipher("wenzhongyu","md5");
// console.log(result);

以上是关于JS加密算法练习的主要内容,如果未能解决你的问题,请参考以下文章