Skip to content

Commit

Permalink
feat(new tool): rsa/ecdsa signing and verify
Browse files Browse the repository at this point in the history
Fix #1084
  • Loading branch information
sharevb committed May 18, 2024
1 parent e876d03 commit e5d8871
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,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 rsaEcdsaSigning } from './rsa-ecdsa-signing';

import { tool as asciiTextDrawer } from './ascii-text-drawer';

Expand Down Expand Up @@ -85,7 +86,21 @@ 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,
passwordStrengthAnalyser,
pdfSignatureChecker,
// pgpEncryption,
rsaEcdsaSigning,
],
},
{
name: 'Converter',
Expand Down
12 changes: 12 additions & 0 deletions src/tools/rsa-ecdsa-signing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Lock } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'RSA/DSA/ECDSA Signer and Verifier',
path: '/rsa-ecdsa-signing',
description: 'Sign data and verify signature using RSA/DSA/ECDSA Keys',
keywords: ['rsa', 'dsa', 'ecdsa', 'ed25519', 'encryption', 'cypher', 'encipher', 'crypt', 'decrypt'],
component: () => import('./rsa-ecdsa-signing.vue'),
icon: Lock,
createdAt: new Date('2024-05-01'),
});
139 changes: 139 additions & 0 deletions src/tools/rsa-ecdsa-signing/rsa-ecdsa-signing.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<script setup lang="ts">
import sshpk from 'sshpk';

Check failure on line 2 in src/tools/rsa-ecdsa-signing/rsa-ecdsa-signing.vue

View workflow job for this annotation

GitHub Actions / ci

Cannot find module 'sshpk' or its corresponding type declarations.
import { computedCatch } from '@/composable/computed/catchedComputed';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const hashTypes = [
'sha1', 'sha256', 'sha384', 'sha512', 'md5',
];
const verifyText = ref('');
const verifySignature = ref('');
const verifyPublicKey = ref('');
const [verifyOutput, verifyError] = computedCatch(() => {
const publicKey = sshpk.parseKey(verifyPublicKey.value, 'auto');
const v = publicKey.createVerify();
v.update(verifyText.value);
return v.verify(verifySignature.value);
}, {
defaultValue: '',
defaultErrorMessage: 'Unable to verify your text',
});
const signText = ref('');
const signPrivateKey = ref('');
const signPrivateKeyPassphrase = ref('');
const signHashType = ref('sha1');
const [signOutput, signError] = computedCatch(() => {
const privateKey = sshpk.parsePrivateKey(signPrivateKey.value, 'auto', { passphrase: signPrivateKeyPassphrase.value });
const s = privateKey.createSign(signHashType.value as sshpk.AlgorithmHashType);
s.update(signText.value);
const signature = s.sign();
return {
asn1: signature.toString('asn1'),
ssh: signature.toString('ssh'),
};
}, {
defaultValue: {
asn1: '',
ssh: '',
},
defaultErrorMessage: 'Unable to sign your text',
});
</script>

<template>
<div>
<c-card title="Sign">
<div>
<c-input-text
v-model:value="signText"
label="Your text:"
placeholder="The string to sign"
rows="4"
multiline raw-text monospace autosize flex-1
/>
<c-select
v-model:value="signHashType"
label="Hash Type:"
:options="hashTypes"
placeholder="Select the hashing algorithm"
/>
<div flex flex-1 flex-col gap-2>
<c-input-text
v-model:value="signPrivateKey"
label="Your private key:"
placeholder="The private key to use to sign message"
rows="5"
multiline raw-text monospace autosize flex-1
/>

<c-input-text
v-model:value="signPrivateKeyPassphrase"
label="Your private key password:" clearable raw-text
/>
</div>
</div>

<c-alert v-if="signError && signPrivateKey !== ''" type="error" mt-12 title="Error while signing">
{{ signError }}
</c-alert>

<n-form-item label="ASN1 Signature:" mt-3>
<TextareaCopyable
:value="signOutput?.asn1 || ''"
placeholder="ASN1 Signature"
multiline monospace readonly autosize mt-5
/>
</n-form-item>
<n-form-item label="SSH Signature:" mt-3>
<TextareaCopyable
:value="signOutput?.ssh || ''"
placeholder="SSG Signature"
multiline monospace readonly autosize mt-5
/>
</n-form-item>
</c-card>
<c-card title="Verify">
<div>
<c-input-text
v-model:value="verifyText"
label="Your text to verify:"
placeholder="The string to verify"
rows="4"
multiline raw-text monospace autosize flex-1
/>

<c-input-text
v-model:value="verifySignature"
label="Associated signature:"
placeholder="Text signature"
rows="4"
multiline raw-text monospace autosize flex-1
/>

<div flex flex-1 flex-col gap-2>
<c-input-text
v-model:value="verifyPublicKey"
label="Public key:"
placeholder="Public key"
rows="5"
multiline raw-text monospace autosize flex-1
/>
</div>
</div>

<c-alert v-if="verifyError && verifyPublicKey !== ''" type="error" mt-12 title="Error while verifying">
{{ verifyError }}
</c-alert>
<c-alert v-if="verifyOutput && verifyPublicKey !== ''" type="error" mt-12 title="Signature failed">
Signature is NOT valid for the given text
</c-alert>
<c-alert v-if="!verifyOutput && verifyPublicKey !== ''" type="success" mt-12 title="Signature verified">
Signature is valid for the given text
</c-alert>
</c-card>
</div>
</template>

0 comments on commit e5d8871

Please sign in to comment.