You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

url-md5

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-md5

> URL MD5 是一个将 url 中的路径和查询参数使用 md5 加密的工具。

0.1.3
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

URL MD5

URL MD5 是一个将 url 中的路径和查询参数使用 md5 加密的工具。

使用指南

使用条件

该项目需要在 node 环境下使用。

安装

npm install url-md5

使用示例

import urlMd5 from "url-md5";

// 传入完整 url
urlMd5.encode("https://www.hostname.com/pathname?a=1&b=2");

// 仅传入 pathname 和 search,适用于 axios 一类使用 basichURL 
urlMd5.encode("/pathname?a=1&b=2");

// 还可以直接传入请求 options
urlMd5.encode({url: "/pathname", method: "POST", params: {a: 1, b: 2}});

详细说明

urlMd5.encode([url,pathname+querystring,options])

encode 函数会将传入的参数格式化成标准的 url 然后截取 pathname+search 进行 md5 加密。

自定义配置

urlMd5.config.salt

你可以定义配置 salt,md5 加密时会将 salt 拼接到 pathname+search 之后。

import urlMd5 from "url-md5";

// 设置 salt
urlMd5.config.salt = "Your salt";

// 示例
urlMd5.encode("https:/www.hostname.com/pathname?a=1&b=2"); // => md5("/pathname?a=1&b=2" + "Your salt");

urlMd5.encode("/pathname?a=1&b=2"); // => md5("/pathname?a=1&b=2" + "Your salt");

urlMd5.encode({url: "/pathname", params: {a: 1, b: 2}}); // => md5("/pathname?a=1&b=2" + "Your salt");

urlMd5.config.pathRewriter(pathname, raw)

如在使用 axios 时,你需要替换加密的 pathname 则可以自定义该函数。

import urlMd5 from "url-md5";

// 设置 pathRewriter
urlMd5.config.pathRewriter = function (pathname, raw) {
    return pathname.replace("/prefix", "") // 将 /prefix/pathname 替换为 /pathname
}

// 示例
urlMd5.encode("https://www.hostname.com/prefix/pathname?a=1&b=2") // => md5("/pathname/?a=1&b=2");

urlMd5.encode("/prefix/pathname?a=1&b=2") // => md5("/pathname/?a=1&b=2");

urlMd5.encode({url: "/prefix/pathname", params: {a: 1, b: 2}}) // => md5("/pathname/?a=1&b=2");

FAQs

Package last updated on 08 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts