mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-25 15:15:23 +03:00
1 parent
6e901196fe
commit
2461cba237
5 files changed
+150
No files matched your search
@@ -297,6 +297,7 @@
|
|||||||
"safe-license-list": "^0.1.2",
|
"safe-license-list": "^0.1.2",
|
||||||
"sandybox": "^1.1.2",
|
"sandybox": "^1.1.2",
|
||||||
"sanitize-html": "^2.14.0",
|
"sanitize-html": "^2.14.0",
|
||||||
|
"shamirs-secret-sharing": "^2.0.1",
|
||||||
"shiki": "1.29.2",
|
"shiki": "1.29.2",
|
||||||
"silly-password-generator": "^1.0.29",
|
"silly-password-generator": "^1.0.29",
|
||||||
"slashes": "^3.0.12",
|
"slashes": "^3.0.12",
|
||||||
|
|||||||
Generated
+8
@@ -779,6 +779,9 @@ importers:
|
|||||||
sanitize-html:
|
sanitize-html:
|
||||||
specifier: ^2.14.0
|
specifier: ^2.14.0
|
||||||
version: 2.14.0
|
version: 2.14.0
|
||||||
|
shamirs-secret-sharing:
|
||||||
|
specifier: ^2.0.1
|
||||||
|
version: 2.0.1
|
||||||
shiki:
|
shiki:
|
||||||
specifier: 1.29.2
|
specifier: 1.29.2
|
||||||
version: 1.29.2
|
version: 1.29.2
|
||||||
@@ -9825,6 +9828,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==}
|
resolution: {integrity: sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
shamirs-secret-sharing@2.0.1:
|
||||||
|
resolution: {integrity: sha512-gB2iE9Wb7BXfO+ExUU+i7/fdjOK7h4+Mtp9ZGRjmdGSeUq3czN+f/gX2KsKJdebXwG09D3SCRH0aqHmEuR2P6A==}
|
||||||
|
|
||||||
sharp@0.34.3:
|
sharp@0.34.3:
|
||||||
resolution: {integrity: sha512-eX2IQ6nFohW4DbvHIOLRB3MHFpYqaqvXd3Tp5e/T/dSH83fxaNJQRvDMhASmkNTsNTVF2/OOopzRCt7xokgPfg==}
|
resolution: {integrity: sha512-eX2IQ6nFohW4DbvHIOLRB3MHFpYqaqvXd3Tp5e/T/dSH83fxaNJQRvDMhASmkNTsNTVF2/OOopzRCt7xokgPfg==}
|
||||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||||
@@ -21562,6 +21568,8 @@ snapshots:
|
|||||||
inherits: 2.0.4
|
inherits: 2.0.4
|
||||||
safe-buffer: 5.2.1
|
safe-buffer: 5.2.1
|
||||||
|
|
||||||
|
shamirs-secret-sharing@2.0.1: {}
|
||||||
|
|
||||||
sharp@0.34.3:
|
sharp@0.34.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
color: 4.2.3
|
color: 4.2.3
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Share } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'Shamirs Secret Sharing',
|
||||||
|
path: '/shamirs-secret-sharing',
|
||||||
|
description: 'Allow to share and recompose a secret using Shamir\'s Secret Sharing algorythm',
|
||||||
|
keywords: ['shamirs', 'secret', 'sharing'],
|
||||||
|
component: () => import('./shamirs-secret-sharing.vue'),
|
||||||
|
icon: Share,
|
||||||
|
createdAt: new Date('2025-11-29'),
|
||||||
|
category: 'Crypto',
|
||||||
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
declare module 'shamirs-secret-sharing' {
|
||||||
|
export function split(secret: Buffer, options: { shares: number, threshold: number }): Buffer[];
|
||||||
|
export function combine(shares: Buffer[]): Buffer;
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Buffer } from 'node:buffer';
|
||||||
|
import sss from 'shamirs-secret-sharing';
|
||||||
|
|
||||||
|
const secret = ref('');
|
||||||
|
const secretMode = ref<'hex' | 'utf8' | 'base64'>('utf8');
|
||||||
|
const shares = ref<string[]>([]);
|
||||||
|
const sharesError = ref('');
|
||||||
|
const threshold = ref(2);
|
||||||
|
const shareCount = ref(3);
|
||||||
|
const recombineInput = ref<string>('');
|
||||||
|
const recombinedSecret = ref('');
|
||||||
|
const recombineError = ref('');
|
||||||
|
|
||||||
|
const secretModes = [
|
||||||
|
{ value: 'utf8', label: 'Text' },
|
||||||
|
{ value: 'hex', label: 'Hexadecimal' },
|
||||||
|
{ value: 'base64', label: 'Base64' },
|
||||||
|
];
|
||||||
|
|
||||||
|
function splitSecret() {
|
||||||
|
if (!secret.value) {
|
||||||
|
shares.value = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sharesError.value = '';
|
||||||
|
try {
|
||||||
|
const secretBuffer = Buffer.from(secret.value, secretMode.value);
|
||||||
|
if (secretBuffer.length === 0) {
|
||||||
|
throw new Error(`Cannot convert "${secret.value}" to ${secretMode.value}`);
|
||||||
|
}
|
||||||
|
const parts = sss.split(secretBuffer, { shares: shareCount.value, threshold: threshold.value });
|
||||||
|
shares.value = parts.map(p => p.toString('hex'));
|
||||||
|
}
|
||||||
|
catch (err: any) {
|
||||||
|
sharesError.value = err.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function recombineSecret() {
|
||||||
|
recombineError.value = '';
|
||||||
|
try {
|
||||||
|
const buffers = recombineInput.value.split('\n').map((hex) => {
|
||||||
|
const buf = Buffer.from(hex, 'hex');
|
||||||
|
if (buf.length === 0) {
|
||||||
|
throw new Error(`Cannot convert "${secret.value}" to ${secretMode.value}`);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
});
|
||||||
|
const result = sss.combine(buffers);
|
||||||
|
recombinedSecret.value = result.toString(secretMode.value);
|
||||||
|
}
|
||||||
|
catch (err: any) {
|
||||||
|
recombineError.value = err.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<c-select
|
||||||
|
v-model:value="secretMode"
|
||||||
|
label="Secret Mode:"
|
||||||
|
label-position="left"
|
||||||
|
:options="secretModes"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
<c-card title="Share a secret (split)">
|
||||||
|
<NForm label-placement="left">
|
||||||
|
<NFormItem label="Secret:">
|
||||||
|
<NInput v-model:value="secret" placeholder="Enter secret text" />
|
||||||
|
</NFormItem>
|
||||||
|
|
||||||
|
<n-space justify="center">
|
||||||
|
<NFormItem label="Threshold (minimum shares to recover):">
|
||||||
|
<NInputNumber v-model:value="threshold" :min="2" />
|
||||||
|
</NFormItem>
|
||||||
|
|
||||||
|
<NFormItem label="Number of shares:">
|
||||||
|
<NInputNumber v-model:value="shareCount" :min="2" />
|
||||||
|
</NFormItem>
|
||||||
|
</n-space>
|
||||||
|
|
||||||
|
<n-space justify="center">
|
||||||
|
<NButton type="primary" @click="splitSecret">
|
||||||
|
Split Secret
|
||||||
|
</NButton>
|
||||||
|
</n-space>
|
||||||
|
</NForm>
|
||||||
|
|
||||||
|
<c-alert v-if="sharesError">
|
||||||
|
{{ sharesError }}
|
||||||
|
</c-alert>
|
||||||
|
<c-card v-if="!sharesError && shares.length" title="Generated Shares">
|
||||||
|
<template v-for="(share, idx) in shares" :key="idx">
|
||||||
|
<input-copyable v-model:value="shares[idx]" readonly mb-1 />
|
||||||
|
</template>
|
||||||
|
</c-card>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card title="Recombine a secret">
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="recombineInput"
|
||||||
|
label="Your shares:"
|
||||||
|
placeholder="Paste your shares here..."
|
||||||
|
rows="5"
|
||||||
|
multiline
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
<n-space justify="center">
|
||||||
|
<NButton type="success" @click="recombineSecret">
|
||||||
|
Recombine
|
||||||
|
</NButton>
|
||||||
|
</n-space>
|
||||||
|
<c-card v-if="!recombineError" title="Recombined secret">
|
||||||
|
<input-copyable :value="recombinedSecret" readonly />
|
||||||
|
</c-card>
|
||||||
|
<c-alert v-else>
|
||||||
|
{{ recombineError }}
|
||||||
|
</c-alert>
|
||||||
|
</c-card>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
Reference in new issue
Block a user