Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加RSA加解密 #209

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/ctool-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export let _tools = {
feature: ['encrypt', 'decrypt'],
parent_directory: "encrypt"
},
rsa: {
feature: ['encrypt', 'decrypt'],
parent_directory: "encrypt"
},
sign: {
feature: ['sign'],
parent_directory: ""
Expand Down Expand Up @@ -152,7 +156,7 @@ export let _tools = {
parent_directory: ""
},
ipcalc: {
feature: ['ipv4','ipv6'],
feature: ['ipv4', 'ipv6'],
parent_directory: ""
},
sqlFillParameter: {
Expand All @@ -171,7 +175,7 @@ export let _tools = {

// 分类 配置
export const _categoryTool: Record<CategoryType, ToolType[]> = {
encryption: ["hash", "aes", "des", "tripleDes", "rc4", "rabbit", "sm2", "sm4", "sign", "base64", "bcrypt"],
encryption: ["hash", "aes", "des", "tripleDes", "rc4", "rabbit", "sm2", "sm4", "rsa", "sign", "base64", "bcrypt"],
check: ["sign", "regex", "diffs", "crontab", "bcrypt", "dataValidation"],
encoder_decoder: ["base64", "url", "unicode", "jwt", "hexString", "html"],
conversion: ["json", "pinyin", "radix", "serialize", "unit", "time", "ascii", "variableConversion", "hexString", "arm", "httpSnippet"],
Expand Down
3 changes: 3 additions & 0 deletions packages/ctool-core/src/i18n/locales/en/tool.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"sm4": "SM4",
"sm4_encrypt": "Encrypt",
"sm4_decrypt": "Decrypt",
"rsa": "RSA",
"rsa_encrypt": "Encrypt",
"rsa_decrypt": "Decrypt",
"sign": "Sign",
"base64": "Base64",
"base64_encoder": "Encoder",
Expand Down
3 changes: 3 additions & 0 deletions packages/ctool-core/src/i18n/locales/zh_CN/tool.i18n.json5
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"sm4": "SM4",
"sm4_encrypt": "加密",
"sm4_decrypt": "解密",
"rsa": "RSA",
"rsa_encrypt": "加密",
"rsa_decrypt": "解密",
"sign": "签名/验签",
"base64": "Base64",
"base64_encoder": "编码",
Expand Down
9 changes: 6 additions & 3 deletions packages/ctool-core/src/tools/encrypt/aes/Decrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
:allow="['text']"
:content="output"
:height="large"
@success="success"
encoding
/>
</Align>
Expand All @@ -46,6 +45,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {modeLists, paddingLists, keySizeLists, aes, Option} from "../cryptoJS"
import {watch} from "vue";

const option: Option = {
iv: "",
Expand Down Expand Up @@ -81,7 +81,10 @@ const output = $computed(() => {
}
})

const success = () => {
watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}
}, {immediate: true, deep: true})
</script>
10 changes: 7 additions & 3 deletions packages/ctool-core/src/tools/encrypt/aes/Encrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<HelpTip link="https://github.com/brix/crypto-js"/>
</template>
</Tabs>
<TextOutput v-model="action.current.output" :allow="['base64','hex']" :content="output" :height="large" @success="success"/>
<TextOutput v-model="action.current.output" :allow="['base64','hex']" :content="output" :height="large"/>
</Align>
</HeightResize>
</template>
Expand All @@ -35,6 +35,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {modeLists, paddingLists, keySizeLists, aes, Option} from "../cryptoJS"
import {watch} from "vue";

const option: Option = {
iv: "",
Expand Down Expand Up @@ -74,7 +75,10 @@ const output = $computed(() => {
}
})

const success = () => {
watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}
}, {immediate: true, deep: true})
</script>
9 changes: 6 additions & 3 deletions packages/ctool-core/src/tools/encrypt/des/Decrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
:allow="['text']"
:content="output"
:height="large"
@success="success"
encoding
/>
</Align>
Expand All @@ -45,6 +44,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {modeLists, paddingLists, des, tripleDES, Option} from "../cryptoJS"
import {watch} from "vue";

const props = defineProps({
type: {
Expand Down Expand Up @@ -86,7 +86,10 @@ const output = $computed(() => {
}
})

const success = () => {
watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}
}, {immediate: true, deep: true})
</script>
9 changes: 6 additions & 3 deletions packages/ctool-core/src/tools/encrypt/des/Encrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
:allow="['base64','hex']"
:content="output"
:height="large"
@success="success"
/>
</Align>
</HeightResize>
Expand All @@ -45,6 +44,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {modeLists, paddingLists, des, tripleDES, Option} from "../cryptoJS"
import {watch} from "vue";

const props = defineProps({
type: {
Expand Down Expand Up @@ -86,7 +86,10 @@ const output = $computed(() => {
}
})

const success = () => {
watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}
}, {immediate: true, deep: true})
</script>
9 changes: 6 additions & 3 deletions packages/ctool-core/src/tools/encrypt/rabbit/Decrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
:allow="['text']"
:content="output"
:height="large"
@success="success"
encoding
/>
</Align>
Expand All @@ -28,6 +27,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {rabbit, Option} from "../cryptoJS"
import {watch} from "vue";

const option: Option = {
key: "",
Expand All @@ -53,7 +53,10 @@ const output = $computed(() => {
}
})

const success = () => {
watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}
}, {immediate: true, deep: true})
</script>
9 changes: 6 additions & 3 deletions packages/ctool-core/src/tools/encrypt/rabbit/Encrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
:allow="['base64','hex']"
:content="output"
:height="large"
@success="success"
/>
</Align>
</HeightResize>
Expand All @@ -28,6 +27,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {rabbit, Option} from "../cryptoJS"
import {watch} from "vue";

const option: Option = {
key: "",
Expand Down Expand Up @@ -56,7 +56,10 @@ const output = $computed<Text>(() => {
}
})

const success = () => {
watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}
}, {immediate: true, deep: true})
</script>
9 changes: 8 additions & 1 deletion packages/ctool-core/src/tools/encrypt/rc4/Decrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
:allow="['text']"
:content="output"
:height="large"
@success="action.save()"
encoding
/>
</Align>
Expand All @@ -28,6 +27,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {rc4, Option} from "../cryptoJS"
import {watch} from "vue";

const option: Option = {
key: "",
Expand All @@ -52,4 +52,11 @@ const output = $computed(() => {
return Text.fromError($error(e))
}
})

watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}, {immediate: true, deep: true})
</script>
9 changes: 8 additions & 1 deletion packages/ctool-core/src/tools/encrypt/rc4/Encrypt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
:allow="['base64','hex']"
:content="output"
:height="large"
@success="action.save()"
/>
</Align>
</HeightResize>
Expand All @@ -28,6 +27,7 @@ import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import {rc4, Option} from "../cryptoJS"
import {watch} from "vue";

const option: Option = {
key: "",
Expand Down Expand Up @@ -55,4 +55,11 @@ const output = $computed<Text>(() => {
return Text.fromError($error(e))
}
})

watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}, {immediate: true, deep: true})
</script>
66 changes: 66 additions & 0 deletions packages/ctool-core/src/tools/encrypt/rsa/Decrypt.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<HeightResize v-slot="{small,large}" ignore :reduce="5">
<Align direction="vertical">
<div v-row="`1-1`">
<Textarea :height="small" v-model="action.current.key" :placeholder="$t(`rsa_private`)"/>
<TextInput
v-model="action.current.input"
:placeholder="$t(`rsa_decrypt_input`)"
:allow="['base64','hex']"
:height="small"
/>
</div>
<Display :position="'top-right'" toggle>
<TextOutput v-model="action.current.output" :content="output" :height="large"/>
<template #extra>
<Select :size="'small'" v-model="action.current.algName" :options="algNames"/>
</template>
</Display>
</Align>
</HeightResize>
</template>

<script lang="ts" setup>
import {useAction, initialize} from "@/store/action"
import {createTextInput, createTextOutput} from "@/components/text"
import Text from "@/helper/text"
import jsrsasign from "jsrsasign";
import {watch} from "vue";

const algNames = [
{value: 'RSA', label: 'PKCS1'},
{value: 'RSAOAEP', label: 'PKCS1_OAEP'}
]

const action = useAction(await initialize({
input: createTextInput('base64'),
algName: "RSA",
key: "",
output: createTextOutput('text'),
}))

const output = $computed(() => {
if (action.current.input.text.isEmpty() || action.current.key.trim() === "") {
return Text.empty()
}
if (action.current.input.text.isError()) {
return action.current.input.text
}
try {
return Text.fromString(jsrsasign.KJUR.crypto.Cipher.decrypt(
action.current.input.text.toHexString(),
jsrsasign.KEYUTIL.getKey(action.current.key.trim()) as jsrsasign.RSAKey,
action.current.algName
))
} catch (e) {
return Text.fromError($error(e))
}
})

watch(() => output, (output) => {
if (output.isEmpty()) {
return
}
action.save()
}, {immediate: true, deep: true})
</script>
Loading