Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
vue3-encryption-plugin
Advanced tools
你的 Pinia 加密插件是一个基于 crypto-js 封装的实用hooks工具,用于在 Vue.js 应用程序中加密和解密敏感数据。它提供了一种简单且安全的方式来保护你的数据。
你可以使用 npm 或 yarn 安装插件:
pnpm i vue3-encryption-plugin
在你的主应用程序入口文件(例如 main.js)中,导入并使用 Pinia store 以及加密插件:
// main.js
import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
// 引入加密插件
import EncryptionPlugin from "vue3-encryption-plugin";
const app = createApp(App);
const pinia = createPinia();
app.use(pinia);
// 注册加密插件并提供自定义的密钥(可选)例如,随机的字符串
app.use(EncryptionPlugin, { key: "your-custom-secret-key" });
app.mount("#app");
一旦你设置了插件,你就可以在组件中使用 $encrypt 和 $decrypt 方法:
第一种: getCurrentInstance()
<!-- YourComponent.vue -->
import { getCurrentInstance } from 'vue';
setup(){
// 获取当前组件的上下文,下面两种方式都能获取到组件的上下文。
const { ctx } = getCurrentInstance(); // 方式一,这种方式只能在开发环境下使用,生产环境 下的ctx将访问不到
const { proxy }: any = getCurrentInstance(); // 方式二,此方法在开发环境以及生产环境下都能到组件上下文对象(推荐)
// ctx 中包含了组件中由ref和reactive创建的响应式数据对象,以及以下对象及方法;
proxy.$attrs
proxy.$data
proxy.$el
proxy.$emit
proxy.$forceUpdate
proxy.$nextTick
proxy.$options
proxy.$parent
proxy.$props
proxy.$refs
proxy.$root
proxy.$slots
proxy.$watch
}
function handClick() {
console.log(
"加密 🚀 ==>:",
proxy.$encryptionPlugin.encrypt({ name: "zk", age: 26})
);
console.log(
"解密 🚀 ==>:",
proxy.$encryptionPlugin.decrypt(
"U2FsdGVkX1/PBDHn2pyLPAf6DmolvylM2QEIDhcf5I3WQWhOh19eos0uZfdbzdDP"
)
);
}
第二种 injict (推荐)
1:src / types / global.d.ts 定义类型
// 加密解密
declare interface EncryptionPlugin {
encryptData: <T>(data: T) => string;
decryptData: <T>(encryptedData: string) => T;
}
如果你使用 eslint
请在 .eslintrc.cjs
文件中添加
globals: {
// 以下是全局变量 eslint 不会报'EncryptionPlugin' is not defined.eslint (no-undef)
EncryptionPlugin: "readonly",
$encryptionPlugin: "readonly",
},
2: 页面使用
<script setup lang="ts">
import { inject } from 'vue';
// 使用 inject 函数获取 encryptionPlugin
const encryptionPlugin = inject("encryptionPlugin") as EncryptionPlugin;
function handClick() {
// 现在你可以在你的组件中使用 encryptData 和 decryptData 方法了
const encryptedData = encryptionPlugin.encryptData("Hello World");
const decryptedData = encryptionPlugin.decryptData(encryptedData);
console.log("加密 🚀 ==>:", encryptedData);
console.log("解密 🚀 ==>:", decryptedData);
}
</script>
FAQs
✈️🔖🔖 pinia插件加密、实现本地数据加密解密
The npm package vue3-encryption-plugin receives a total of 1 weekly downloads. As such, vue3-encryption-plugin popularity was classified as not popular.
We found that vue3-encryption-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.