cure-utlis
v0.0.2
Published
A universal toolkit encompassing network requests, various encryption methods, and JWT
Readme
cure-utlis toolkit
A universal toolkit encompassing network requests, various encryption methods, and JWT
network request
// instantiation
const a = new network({
baseUrl: 'https://api.aosda.cn',
})
interceptors
// Request Interceptor
a.interceptors.request((config) => {
config.headers['Content-Type'] = 'application/json; charset=UTF-8';
return config;
} )
// Response interceptors
a.interceptors.response((response: any) => {
console.log(response.headers);
return response.data;
})
a.get("/index/wallpaperClassify", {
params: {
pageNum: "1"
}
}).then(r => {
console.log(r)
})
a.post("/auth/phone/sign_in", {
username: 'admin',
password: 'wdsj102030Q',
}).then(response => {
console.log(response);
})
a.put()
a.delete()
encryption
console.log(Encryption.createHmac("asdasdasdas", 'asdasdasdasdas'))
// 74423d2d7515cb24bbde4898f9cf8e77a6931f84f07ad877b23d938aa741aa95
md5Encrypt(text) MD5 encryption
sha256Encrypt(text) SHA-256 encrypted password
sha512Encrypt(text) SHA-512 encrypted password
createHmac(text, key, algorithm) HMAC encryption
encryptByAes256(content, secretKey, iv)
decryptByAes256(content, secretKey, iv)
rsaEncrypt(data, publicKey)
rsaDecrypt(encryptedData, privateKey)
JWT
// generate token
JWTUtils.sign({
userId: 1
}, "yyyyyy", {
expiresIn: 3600
}).then( res => {
console.log(res);
})
// Verify the token and obtain the stored userId
JWTUtils.verify("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjA0NTUwOTAsImV4cCI6MTc2MDQ1ODY5MCwidXNlcklkIjoxfQ.MmVkZDBiN2I", "yyyyyy")
Continuously updating with more functions
