@particle-network/common
Advanced tools
Comparing version 0.1.1 to 0.1.2
declare type DataEncoding = "base64" | "hex"; | ||
export declare function encryptUrlParam(params?: {}): string; | ||
export declare function encryptUrlParam(params?: {}, encoding?: DataEncoding, secretKey?: string): string; | ||
export declare function decryptUrlParam(params: string, encoding?: DataEncoding): string; | ||
export {}; |
@@ -9,8 +9,11 @@ "use strict"; | ||
var uuid_1 = require("uuid"); | ||
function encryptUrlParam(params) { | ||
function encryptUrlParam(params, encoding, secretKey) { | ||
if (params === void 0) { params = {}; } | ||
if (encoding === void 0) { encoding = "base64"; } | ||
if (typeof params !== "string") { | ||
params = JSON.stringify(params); | ||
} | ||
var secretKey = (0, uuid_1.v4)().replace(/-/g, "").toUpperCase(); | ||
if (!secretKey) { | ||
secretKey = (0, uuid_1.v4)().replace(/-/g, "").toUpperCase(); | ||
} | ||
var keyWA = crypto_js_1.default.enc.Utf8.parse(secretKey); | ||
@@ -23,3 +26,8 @@ var cipherText = crypto_js_1.default.AES.encrypt(params, keyWA, { | ||
}).ciphertext; | ||
return encodeURIComponent(crypto_js_1.default.enc.Base64.stringify(cipherText)) + secretKey; | ||
if (encoding === "base64") { | ||
return encodeURIComponent(crypto_js_1.default.enc.Base64.stringify(cipherText)) + secretKey; | ||
} | ||
else { | ||
return crypto_js_1.default.enc.Hex.stringify(cipherText).toUpperCase() + secretKey; | ||
} | ||
} | ||
@@ -26,0 +34,0 @@ exports.encryptUrlParam = encryptUrlParam; |
{ | ||
"name": "@particle-network/common", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26139
308