-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new tool): rsa/ecdsa signing and verify
Fix #1084
- Loading branch information
Showing
3 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<script setup lang="ts"> | ||
import sshpk from 'sshpk'; | ||
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> |