Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue3-encryption-plugin

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue3-encryption-plugin - npm Package Compare versions

Comparing version 1.0.3 to 1.0.5

4

package.json
{
"name": "vue3-encryption-plugin",
"version": "1.0.3",
"description": "🎉🎉🔥 pinia插件加密、实现本地数据加密解密",
"version": "1.0.5",
"description": "✈️🔖🔖 pinia插件加密、实现本地数据加密解密",
"main": "src/index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -22,2 +22,3 @@ # 你的 Pinia 加密插件

import App from "./App.vue";
// 引入加密插件
import EncryptionPlugin from "vue3-encryption-plugin";

@@ -67,8 +68,8 @@

console.log(
"!这里输出 🚀 ==>:",
proxy.$encryptionPlugin.encryptData({ name: "zk", age: 26})
"加密 🚀 ==>:",
proxy.$encryptionPlugin.encrypt({ name: "zk", age: 26})
);
console.log(
"!这里输出 🚀 ==>:",
proxy.$encryptionPlugin.decryptData(
"解密 🚀 ==>:",
proxy.$encryptionPlugin.decrypt(
"U2FsdGVkX1/PBDHn2pyLPAf6DmolvylM2QEIDhcf5I3WQWhOh19eos0uZfdbzdDP"

@@ -92,3 +93,3 @@ )

如果你使用 eslint 请在 .eslintrc.cjs 文件中添加
如果你使用 `eslint` 请在 `.eslintrc.cjs` 文件中添加

@@ -95,0 +96,0 @@ ```javascript

@@ -0,29 +1,34 @@

// 导入所需的加密库
import CryptoJS from "crypto-js";
// 加密函数
const encryptData = (data, key) => {
const encryptedData = CryptoJS.AES.encrypt(
JSON.stringify(data),
key
).toString();
return encryptedData;
};
// 解密函数
const decryptData = (encryptedData, key) => {
const decryptedBytes = CryptoJS.AES.decrypt(encryptedData, key);
const decryptedData = JSON.parse(decryptedBytes.toString(CryptoJS.enc.Utf8));
return decryptedData;
};
// 定义插件接口
const EncryptionPlugin = {
install: (app, options) => {
// 加密密钥,默认使用一个固定值,你可以根据实际情况进行配置
const key = options && options.key ? options.key : "my-secret-key";
const EncryptionPlugin = {
install: (app, { key = "my-secret-key" } = {}) => {
// 为组件提供插件
app.provide("encryptionPlugin", {
encryptData: (data) => encryptData(data, key),
decryptData: (data) => decryptData(data, key),
// 加密函数
const encryptData = (data) => {
const encryptedData = CryptoJS.AES.encrypt(
JSON.stringify(data),
key
).toString();
return encryptedData;
};
// 解密函数
const decryptData = (encryptedData) => {
const decryptedBytes = CryptoJS.AES.decrypt(encryptedData, key);
const decryptedData = JSON.parse(
decryptedBytes.toString(CryptoJS.enc.Utf8)
);
return decryptedData;
};
app.config.globalProperties.$encrypt = encryptData;
app.config.globalProperties.$decrypt = decryptData;
provide("encryptionPlugin", {
encryptData,
decryptData,
});
app.config.globalProperties.$encryptionPlugin = {
encryptData: (data) => encryptData(data, key),
decryptData: (data) => decryptData(data, key),
};
},

@@ -30,0 +35,0 @@ };

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc