it-tools/src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue

50 lines
1.5 KiB
Vue
Raw Normal View History

2023-03-10 18:16:55 +01:00
<script setup lang="ts">
import { generateKeyPair } from './rsa-key-pair-generator.service';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
2023-03-10 18:16:55 +01:00
import { withDefaultOnErrorAsync } from '@/utils/defaults';
import { useValidation } from '@/composable/validation';
import { computedRefreshableAsync } from '@/composable/computedRefreshable';
2023-03-10 18:16:55 +01:00
const bits = ref(2048);
const emptyCerts = { publicKeyPem: '', privateKeyPem: '' };
const { attrs: bitsValidationAttrs } = useValidation({
source: bits,
rules: [
{
message: 'Bits should be 256 <= bits <= 16384 and be a multiple of 8',
validator: value => value >= 256 && value <= 16384 && value % 8 === 0,
2023-03-10 18:16:55 +01:00
},
],
});
const [certs, refreshCerts] = computedRefreshableAsync(
2023-03-10 18:16:55 +01:00
() => withDefaultOnErrorAsync(() => generateKeyPair({ bits: bits.value }), emptyCerts),
emptyCerts,
);
</script>
<template>
<div style="flex: 0 0 100%">
<div item-style="flex: 1 1 0" style="max-width: 600px" mx-auto flex gap-3>
<n-form-item label="Bits :" v-bind="bitsValidationAttrs as any" label-placement="left" label-width="100">
<n-input-number v-model:value="bits" min="256" max="16384" step="8" />
</n-form-item>
<c-button @click="refreshCerts">
Refresh key-pair
</c-button>
</div>
</div>
<div>
<h3>Public key</h3>
<TextareaCopyable :value="certs.publicKeyPem" />
</div>
<div>
<h3>Private key</h3>
<TextareaCopyable :value="certs.privateKeyPem" />
</div>
</template>