Skip to content

Commit 82d99b6

Browse files
committed
feat(new tool): Ansible Vault Encrypt/Decrypt
Fix CorentinTh#896 and CorentinTh#875
1 parent a07806c commit 82d99b6

File tree

5 files changed

+150
-7
lines changed

5 files changed

+150
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@vueuse/core": "^10.3.0",
4747
"@vueuse/head": "^1.0.0",
4848
"@vueuse/router": "^10.0.0",
49+
"ansible-vault": "^1.1.1",
4950
"bcryptjs": "^2.4.3",
5051
"change-case": "^4.1.2",
5152
"colord": "^2.9.3",

pnpm-lock.yaml

Lines changed: 19 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<script setup lang="ts">
2+
import { Vault } from 'ansible-vault';
3+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
4+
5+
const decryptedInput = ref('');
6+
const encryptPassword = ref('');
7+
const encryptId = ref('');
8+
const cryptedOutput = computedAsync(
9+
async () => {
10+
try {
11+
const v = new Vault({ password: encryptPassword.value });
12+
return await v.encrypt(decryptedInput.value, encryptId.value);
13+
}
14+
catch (e: any) {
15+
return e.toString();
16+
}
17+
},
18+
);
19+
20+
const cryptedInput = ref('');
21+
const decryptPassword = ref('');
22+
const decryptedOutput = computedAsync(
23+
async () => {
24+
try {
25+
const v = new Vault({ password: decryptPassword.value });
26+
// handle mac \r
27+
return (await v.decrypt(cryptedInput.value?.replace(/\r(?!\n)/, '\n'), undefined)) ?? '';
28+
}
29+
catch (e: any) {
30+
return e.toString();
31+
}
32+
},
33+
);
34+
</script>
35+
36+
<template>
37+
<c-card title="Encrypt Ansible Vault Secret">
38+
<c-input-text
39+
v-model:value="decryptedInput"
40+
placeholder="Put your string to encrypt..."
41+
label="String to encrypt"
42+
raw-text
43+
mb-5
44+
/>
45+
46+
<n-space>
47+
<c-input-text
48+
v-model:value="encryptPassword"
49+
placeholder="Encryption password"
50+
label="Encryption password"
51+
raw-text
52+
mb-5
53+
/>
54+
<c-input-text
55+
v-model:value="encryptId"
56+
placeholder="Encryption Id"
57+
label="Encryption Id"
58+
raw-text
59+
mb-5
60+
/>
61+
</n-space>
62+
63+
<n-divider />
64+
65+
<TextareaCopyable
66+
label="Encrypted string"
67+
:value="cryptedOutput"
68+
multiline
69+
readonly
70+
rows="5"
71+
mb-5
72+
/>
73+
</c-card>
74+
75+
<c-card title="Decrypt Ansible Vault Secret">
76+
<c-input-text
77+
v-model:value="cryptedInput"
78+
placeholder="Put your encrypted string here..."
79+
label="String to decrypt"
80+
raw-text multiline mb-5
81+
rows="5"
82+
/>
83+
84+
<c-input-text
85+
v-model:value="decryptPassword"
86+
placeholder="Decryption password"
87+
label="Decryption password"
88+
raw-text
89+
mb-5
90+
/>
91+
92+
<n-divider />
93+
94+
<TextareaCopyable
95+
label="Decrypted string"
96+
:value="decryptedOutput"
97+
multiline
98+
readonly
99+
rows="5"
100+
mb-5
101+
/>
102+
</c-card>
103+
</template>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { LockSquare } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Ansible vault crypt decrypt',
6+
path: '/ansible-vault-crypt-decrypt',
7+
description: 'Encrypt and decrypt Ansible Vault Secrets',
8+
keywords: ['ansible', 'vault', 'crypt', 'decrypt'],
9+
component: () => import('./ansible-vault-crypt-decrypt.vue'),
10+
icon: LockSquare,
11+
createdAt: new Date('2024-02-25'),
12+
});

src/tools/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
22
import { tool as base64StringConverter } from './base64-string-converter';
33
import { tool as basicAuthGenerator } from './basic-auth-generator';
44
import { tool as textToUnicode } from './text-to-unicode';
5+
import { tool as ansibleVaultCryptDecrypt } from './ansible-vault-crypt-decrypt';
56
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
67
import { tool as numeronymGenerator } from './numeronym-generator';
78
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -81,7 +82,20 @@ import { tool as yamlViewer } from './yaml-viewer';
8182
export const toolsByCategory: ToolCategory[] = [
8283
{
8384
name: 'Crypto',
84-
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker],
85+
components: [
86+
tokenGenerator,
87+
hashText,
88+
bcrypt,
89+
uuidGenerator,
90+
ulidGenerator,
91+
cypher,
92+
bip39,
93+
hmacGenerator,
94+
rsaKeyPairGenerator,
95+
ansibleVaultCryptDecrypt,
96+
passwordStrengthAnalyser,
97+
pdfSignatureChecker,
98+
],
8599
},
86100
{
87101
name: 'Converter',

0 commit comments

Comments
 (0)