feat(new tool): Ansible Vault Encrypt/Decrypt

Fix #896 and #875
This commit is contained in:
sharevb 2024-03-03 09:26:15 +01:00 committed by ShareVB
parent a07806cd15
commit 82d99b6965
5 changed files with 150 additions and 7 deletions

View file

@ -0,0 +1,103 @@
<script setup lang="ts">
import { Vault } from 'ansible-vault';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const decryptedInput = ref('');
const encryptPassword = ref('');
const encryptId = ref('');
const cryptedOutput = computedAsync(
async () => {
try {
const v = new Vault({ password: encryptPassword.value });
return await v.encrypt(decryptedInput.value, encryptId.value);
}
catch (e: any) {
return e.toString();
}
},
);
const cryptedInput = ref('');
const decryptPassword = ref('');
const decryptedOutput = computedAsync(
async () => {
try {
const v = new Vault({ password: decryptPassword.value });
// handle mac \r
return (await v.decrypt(cryptedInput.value?.replace(/\r(?!\n)/, '\n'), undefined)) ?? '';
}
catch (e: any) {
return e.toString();
}
},
);
</script>
<template>
<c-card title="Encrypt Ansible Vault Secret">
<c-input-text
v-model:value="decryptedInput"
placeholder="Put your string to encrypt..."
label="String to encrypt"
raw-text
mb-5
/>
<n-space>
<c-input-text
v-model:value="encryptPassword"
placeholder="Encryption password"
label="Encryption password"
raw-text
mb-5
/>
<c-input-text
v-model:value="encryptId"
placeholder="Encryption Id"
label="Encryption Id"
raw-text
mb-5
/>
</n-space>
<n-divider />
<TextareaCopyable
label="Encrypted string"
:value="cryptedOutput"
multiline
readonly
rows="5"
mb-5
/>
</c-card>
<c-card title="Decrypt Ansible Vault Secret">
<c-input-text
v-model:value="cryptedInput"
placeholder="Put your encrypted string here..."
label="String to decrypt"
raw-text multiline mb-5
rows="5"
/>
<c-input-text
v-model:value="decryptPassword"
placeholder="Decryption password"
label="Decryption password"
raw-text
mb-5
/>
<n-divider />
<TextareaCopyable
label="Decrypted string"
:value="decryptedOutput"
multiline
readonly
rows="5"
mb-5
/>
</c-card>
</template>

View file

@ -0,0 +1,12 @@
import { LockSquare } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Ansible vault crypt decrypt',
path: '/ansible-vault-crypt-decrypt',
description: 'Encrypt and decrypt Ansible Vault Secrets',
keywords: ['ansible', 'vault', 'crypt', 'decrypt'],
component: () => import('./ansible-vault-crypt-decrypt.vue'),
icon: LockSquare,
createdAt: new Date('2024-02-25'),
});

View file

@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as ansibleVaultCryptDecrypt } from './ansible-vault-crypt-decrypt';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@ -81,7 +82,20 @@ import { tool as yamlViewer } from './yaml-viewer';
export const toolsByCategory: ToolCategory[] = [
{
name: 'Crypto',
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker],
components: [
tokenGenerator,
hashText,
bcrypt,
uuidGenerator,
ulidGenerator,
cypher,
bip39,
hmacGenerator,
rsaKeyPairGenerator,
ansibleVaultCryptDecrypt,
passwordStrengthAnalyser,
pdfSignatureChecker,
],
},
{
name: 'Converter',