aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Corentin Thomasset <corentin.thomasset74@gmail.com> 2022-08-03 13:59:45 +0200
committerGravatar Corentin THOMASSET <corentin.thomasset74@gmail.com> 2022-08-03 17:19:53 +0200
commit1bc6380c6fdd7a9b500422a54bc508ab5557eb46 (patch)
tree7b0be951dd0ce09e28543054bd2097a486c146d8 /src
parent02c49635315661ca08deb0859c5ba33113368b9b (diff)
downloadit-tools-1bc6380c6fdd7a9b500422a54bc508ab5557eb46.tar.gz
it-tools-1bc6380c6fdd7a9b500422a54bc508ab5557eb46.tar.zst
it-tools-1bc6380c6fdd7a9b500422a54bc508ab5557eb46.zip
feat(new-tool): hmac generator
Diffstat (limited to 'src')
-rw-r--r--src/tools/hmac-generator/hmac-generator.vue98
-rw-r--r--src/tools/hmac-generator/index.ts12
-rw-r--r--src/tools/index.ts3
3 files changed, 112 insertions, 1 deletions
diff --git a/src/tools/hmac-generator/hmac-generator.vue b/src/tools/hmac-generator/hmac-generator.vue
new file mode 100644
index 0000000..73669df
--- /dev/null
+++ b/src/tools/hmac-generator/hmac-generator.vue
@@ -0,0 +1,98 @@
+<template>
+ <div>
+ <n-form-item label="Plain text to compute the hash">
+ <n-input v-model:value="plainText" type="textarea" placeholder="Enter the text to compute the hash..." />
+ </n-form-item>
+ <n-form-item label="Secret key">
+ <n-input v-model:value="secret" placeholder="Enter the secret key..." />
+ </n-form-item>
+ <n-space item-style="flex:1 1 0">
+ <n-form-item label="Hashing function">
+ <n-select
+ v-model:value="hashFunction"
+ placeholder="Select an hashing function..."
+ :options="Object.keys(algos).map((label) => ({ label, value: label }))"
+ />
+ </n-form-item>
+ <n-form-item label="Output encoding">
+ <n-select
+ v-model:value="encoding"
+ placeholder="Select the result encoding..."
+ :options="[
+ {
+ label: 'Binary (base 2)',
+ value: 'Bin',
+ },
+ {
+ label: 'Hexadecimal (base 16)',
+ value: 'Hex',
+ },
+ {
+ label: 'Base64 (base 64)',
+ value: 'Base64',
+ },
+ {
+ label: 'Base64-url (base 64 with url safe chars)',
+ value: 'Base64url',
+ },
+ ]"
+ />
+ </n-form-item>
+ </n-space>
+ <n-form-item label="HMAC of your text">
+ <n-input readonly :value="hmac" type="textarea" placeholder="The result of the HMAC..." />
+ </n-form-item>
+ <n-space justify="center">
+ <n-button secondary @click="copy()">Copy HMAC</n-button>
+ </n-space>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { useCopy } from '@/composable/copy.js';
+import {
+ enc,
+ HmacMD5,
+ HmacRIPEMD160,
+ HmacSHA1,
+ HmacSHA224,
+ HmacSHA256,
+ HmacSHA3,
+ HmacSHA384,
+ HmacSHA512,
+ lib,
+} from 'crypto-js';
+import { computed, ref } from 'vue';
+import { convertHexToBin } from '../hash-text/hash-text.service.js';
+
+const algos = {
+ MD5: HmacMD5,
+ RIPEMD160: HmacRIPEMD160,
+ SHA1: HmacSHA1,
+ SHA3: HmacSHA3,
+ SHA224: HmacSHA224,
+ SHA256: HmacSHA256,
+ SHA384: HmacSHA384,
+ SHA512: HmacSHA512,
+} as const;
+
+type Encoding = keyof typeof enc | 'Bin';
+
+function formatWithEncoding(words: lib.WordArray, encoding: Encoding) {
+ if (encoding === 'Bin') {
+ return convertHexToBin(words.toString(enc.Hex));
+ }
+ return words.toString(enc[encoding]);
+}
+
+const plainText = ref('');
+const secret = ref('');
+const hashFunction = ref<keyof typeof algos>('SHA256');
+const encoding = ref<Encoding>('Hex');
+const hmac = computed(() =>
+ formatWithEncoding(algos[hashFunction.value](plainText.value, secret.value), encoding.value),
+);
+const { copy } = useCopy({ source: hmac });
+</script>
+
+<style lang="less" scoped></style>
diff --git a/src/tools/hmac-generator/index.ts b/src/tools/hmac-generator/index.ts
new file mode 100644
index 0000000..c0ca7da
--- /dev/null
+++ b/src/tools/hmac-generator/index.ts
@@ -0,0 +1,12 @@
+import { ShortTextRound } from '@vicons/material';
+import { defineTool } from '../tool';
+
+export const tool = defineTool({
+ name: 'Hmac generator',
+ path: '/hmac-generator',
+ description:
+ 'Computes a hash-based message authentication code (HMAC) using a secret key and your favorite hashing function.',
+ keywords: ['hmac', 'generator', 'MD5', 'SHA1', 'SHA256', 'SHA224', 'SHA512', 'SHA384', 'SHA3', 'RIPEMD160'],
+ component: () => import('./hmac-generator.vue'),
+ icon: ShortTextRound,
+});
diff --git a/src/tools/index.ts b/src/tools/index.ts
index 6f30200..a03f273 100644
--- a/src/tools/index.ts
+++ b/src/tools/index.ts
@@ -16,6 +16,7 @@ import { tool as cypher } from './encryption';
import { tool as etaCalculator } from './eta-calculator';
import { tool as gitMemo } from './git-memo';
import { tool as hashText } from './hash-text';
+import { tool as hmacGenerator } from './hmac-generator';
import { tool as htmlEntities } from './html-entities';
import { tool as baseConverter } from './integer-base-converter';
import { tool as jsonViewer } from './json-viewer';
@@ -36,7 +37,7 @@ export const toolsByCategory: ToolCategory[] = [
{
name: 'Crypto',
icon: LockOpen,
- components: [tokenGenerator, hashText, bcrypt, uuidGenerator, cypher, bip39],
+ components: [tokenGenerator, hashText, bcrypt, uuidGenerator, cypher, bip39, hmacGenerator],
},
{
name: 'Converter',