https://github.com/tpenaranda/vue-cryptojs
A small wrapper for integrating crypto-js into VueJS
https://github.com/tpenaranda/vue-cryptojs
crypto-js decrypt encrypt vue-cryptojs vuejs wrapper
Last synced: 8 months ago
JSON representation
A small wrapper for integrating crypto-js into VueJS
- Host: GitHub
- URL: https://github.com/tpenaranda/vue-cryptojs
- Owner: tpenaranda
- License: other
- Created: 2019-10-13T01:09:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-18T02:58:27.000Z (almost 2 years ago)
- Last Synced: 2025-01-10T14:13:14.007Z (over 1 year ago)
- Topics: crypto-js, decrypt, encrypt, vue-cryptojs, vuejs, wrapper
- Language: JavaScript
- Size: 331 KB
- Stars: 18
- Watchers: 3
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vue-cryptojs
A small wrapper for integrating crypto-js into Vue3 and Vue2
## Discontinued
Active development of Vue-CryptoJS has been discontinued. This library is no longer maintained.
Nowadays, NodeJS and modern browsers have a native `Crypto` module. The latest version of CryptoJS already uses the native Crypto module for random number generation, since `Math.random()` is not crypto-safe. Further development of CryptoJS would result in it only being a wrapper of native Crypto. Therefore, development and maintenance has been discontinued, it is time to go for the native `crypto` module.
## How to install:
```bash
npm install vue-cryptojs
```
### Vue3
Entry file:
```js
import { createApp } from 'vue'
import VueCryptojs from 'vue-cryptojs'
createApp(...).use(VueCryptojs).mount(...)
```
TS Component:
```js
import { inject } from 'vue'
import CryptoJS from 'crypto-js'
const cryptojs = inject('cryptojs') as typeof CryptoJS
{{cryptojs.AES.encrypt("Hi There!", "Secret Passphrase").toString()}}
{{cryptojs.AES.decrypt("U2FsdGVkX1/zclTGSirKJ+oYxGJFRR96i9MkjOb8X0s=", "Secret Passphrase").toString(cryptojs.enc.Utf8)}}
```
`inject` on Composition API without TS:
```js
import { inject } from 'vue'
export default {
setup() {
const cryoptojs = inject('cryptojs')
return {
cryoptojs
}
}
}
```
### Vue2
```js
import Vue from 'vue'
import VueCryptojs from 'vue-cryptojs'
Vue.use(VueCryptojs)
```
This binds `CryptoJS` to `Vue` or `this` if you're using single file component.
Simple AES text encrypt/decrypt example:
```js
const encryptedText = this.$CryptoJS.AES.encrypt("Hi There!", "Secret Passphrase").toString()
const decryptedText = this.$CryptoJS.AES.decrypt(encryptedText, "Secret Passphrase").toString(this.$CryptoJS.enc.Utf8)
```
Directly on a template:
```js
{{ $CryptoJS.AES.encrypt("Hi There!", "Secret Passphrase").toString() }}
```
Please kindly check full documention of [crypto-js](https://github.com/brix/crypto-js)