it-tools/tools/crypto/cypher-uncyfer-text.vue

102 lines
2.2 KiB
Vue
Raw Normal View History

2021-03-14 20:11:39 +01:00
<template>
2021-05-28 19:44:27 +02:00
<ToolWrapper :config="$toolConfig">
2021-03-14 20:11:39 +01:00
<v-row justify="center" align="center">
<v-col cols="12" lg="8" md="12">
<v-textarea
v-model="key"
outlined
label="Encryption key"
rows="1"
@input="encrypt"
/>
</v-col>
<v-col cols="12" lg="4" md="12">
<v-select
v-model="algorithm"
:items="Object.keys(algorithms)"
label="Algorithm"
outlined
@change="encrypt"
/>
</v-col>
</v-row>
<v-textarea
v-model="decrypted"
outlined
label="Clear text"
@input="encrypt"
/>
<v-textarea
v-model="encrypted"
outlined
label="Cyphered text"
@input="decrypt"
/>
<div class="text-center">
<v-btn depressed @click="copy(encrypted)">
Copy result
</v-btn>
</div>
</ToolWrapper>
</template>
2021-05-28 19:44:27 +02:00
<tool>
title: 'Cypher / uncypher text'
description: 'Cypher and uncyfer text.'
icon: 'mdi-lock-open'
keywords: ['cypher', 'uncypher', 'text', 'AES', 'TripleDES', 'Rabbit', 'RabbitLegacy', 'RC4']
path: '/cypher-uncyfer-text'
</tool>
2021-03-14 20:11:39 +01:00
<script lang="ts">
import {Component} from 'nuxt-property-decorator'
import {CopyableMixin} from '@/mixins/copyable.mixin'
2021-03-14 21:20:35 +01:00
import Tool from '@/components/Tool.vue'
2021-03-14 20:11:39 +01:00
import CryptoJS from 'crypto-js'
const algos = {
AES: CryptoJS.AES,
TripleDES: CryptoJS.TripleDES,
Rabbit: CryptoJS.Rabbit,
RabbitLegacy: CryptoJS.RabbitLegacy,
RC4: CryptoJS.RC4
}
@Component({
mixins: [CopyableMixin]
})
export default class CypherUncyferText extends Tool {
algorithm: keyof typeof algos = 'AES'
algorithms: typeof algos = algos
key = 'sup3r s3cr3t k3y'
decrypted = 'Lorem ipsum dolor sit amet.'
encrypted = ''
mounted() {
this.encrypt()
}
encrypt() {
try {
this.encrypted = this.algorithms[this.algorithm]
.encrypt(this.decrypted.trim(), this.key)
.toString()
} catch (ignored) {
// ignored
}
}
decrypt() {
try {
this.decrypted = this.algorithms[this.algorithm]
.decrypt(this.encrypted.trim(), this.key)
.toString(CryptoJS.enc.Utf8)
} catch (ignored) {
// ignored
}
}
}
</script>