From f5597d208d362cd935cc02c65f3dc545bba79952 Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 18 Apr 2022 20:16:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E9=9D=9E=E5=AF=B9=E7=A7=B0?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E7=AE=97=E6=B3=95=E4=BD=8D=E6=95=B0=E9=80=89?= =?UTF-8?q?=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/leon/view/AsymmetricCryptoView.kt | 32 +++++++++++++------ app/src/main/resources/Messages.properties | 2 +- app/src/main/resources/Messages_en.properties | 2 +- .../main/resources/Messages_zh_CN.properties | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/me/leon/view/AsymmetricCryptoView.kt b/app/src/main/kotlin/me/leon/view/AsymmetricCryptoView.kt index 75bfa2052d..974be93dca 100644 --- a/app/src/main/kotlin/me/leon/view/AsymmetricCryptoView.kt +++ b/app/src/main/kotlin/me/leon/view/AsymmetricCryptoView.kt @@ -1,8 +1,6 @@ package me.leon.view -import javafx.beans.property.SimpleBooleanProperty -import javafx.beans.property.SimpleIntegerProperty -import javafx.beans.property.SimpleStringProperty +import javafx.beans.property.* import javafx.scene.control.* import me.leon.Styles import me.leon.controller.AsymmetricCryptoController @@ -18,6 +16,7 @@ class AsymmetricCryptoView : Fragment(FX.messages["asymmetric"]) { private val isSingleLine = SimpleBooleanProperty(false) private val privateKeyEncrypt = SimpleBooleanProperty(false) private val isProcessing = SimpleBooleanProperty(false) + private var cbBits :ComboBox by singleAssign() lateinit var taInput: TextArea lateinit var taKey: TextArea lateinit var taOutput: TextArea @@ -35,7 +34,7 @@ class AsymmetricCryptoView : Fragment(FX.messages["asymmetric"]) { private var startTime = 0L private val info get() = - "RSA bits: ${selectedBits.get()} mode: ${ + "${selectedAlg.get()} bits: ${selectedBits.get()} mode: ${ if (privateKeyEncrypt.get()) "private key encrypt" else "public key encrypt" } cost: $timeConsumption ms" @@ -52,16 +51,22 @@ class AsymmetricCryptoView : Fragment(FX.messages["asymmetric"]) { } private val alg - get() = selecteAlg.get() + get() = selectedAlg.get() private var isEncrypt = true private var inputEncode = "raw" private var outputEncode = "base64" private lateinit var tgInput: ToggleGroup private lateinit var tgOutput: ToggleGroup + private val algoMaps = mapOf( + "RSA" to listOf(512, 1024, 2048, 3072, 4096), + "ElGamal" to listOf(512, 1024, 2048), + "SM2" to listOf(256), + + ) private val bitsLists = mutableListOf(512, 1024, 2048, 3072, 4096) - private val algs = listOf("RSA", "ElGamal", "SM2") - private val selectedBits = SimpleIntegerProperty(1024) - private val selecteAlg = SimpleStringProperty(algs.first()) + private val algs = algoMaps.keys.toMutableList() + private val selectedAlg = SimpleStringProperty(algs.first()) + private val selectedBits = SimpleIntegerProperty(algoMaps[selectedAlg.get()]!!.first()) private val isPrivateKey get() = isEncrypt && privateKeyEncrypt.get() || !isEncrypt && !privateKeyEncrypt.get() @@ -151,9 +156,16 @@ class AsymmetricCryptoView : Fragment(FX.messages["asymmetric"]) { hbox { addClass(Styles.left) label(messages["alg"]) - combobox(selecteAlg, algs) { cellFormat { text = it.toString() } } + combobox(selectedAlg, algs) { cellFormat { text = it.toString() } } + selectedAlg.addListener { _, _, newValue -> + newValue?.run { + cbBits.items = algoMaps[newValue]!!.asObservable() + selectedBits.set(algoMaps[newValue]!!.first()) + cbBits.isDisable = algoMaps[newValue]!!.size == 1 + } + } label(messages["bits"]) - combobox(selectedBits, bitsLists) { cellFormat { text = it.toString() } } + cbBits = combobox(selectedBits, bitsLists) { cellFormat { text = it.toString() } } togglegroup { spacing = DEFAULT_SPACING radiobutton(messages["encrypt"]) { isSelected = true } diff --git a/app/src/main/resources/Messages.properties b/app/src/main/resources/Messages.properties index 2d4e2e77f3..ab73071295 100644 --- a/app/src/main/resources/Messages.properties +++ b/app/src/main/resources/Messages.properties @@ -8,7 +8,7 @@ encodeTransfer=EncodeTransfer about=about symmetricBlock=Symmetric(Block) symmetricStream=Symmetric(Stream) -asymmetric= Asymmetric(RSA) +asymmetric= Asymmetric encrypt=encrypt decrypt=decrypt fileMode=file mode diff --git a/app/src/main/resources/Messages_en.properties b/app/src/main/resources/Messages_en.properties index 2d4e2e77f3..ab73071295 100644 --- a/app/src/main/resources/Messages_en.properties +++ b/app/src/main/resources/Messages_en.properties @@ -8,7 +8,7 @@ encodeTransfer=EncodeTransfer about=about symmetricBlock=Symmetric(Block) symmetricStream=Symmetric(Stream) -asymmetric= Asymmetric(RSA) +asymmetric= Asymmetric encrypt=encrypt decrypt=decrypt fileMode=file mode diff --git a/app/src/main/resources/Messages_zh_CN.properties b/app/src/main/resources/Messages_zh_CN.properties index 295fad045a..b5cd41501e 100644 --- a/app/src/main/resources/Messages_zh_CN.properties +++ b/app/src/main/resources/Messages_zh_CN.properties @@ -8,7 +8,7 @@ encodeTransfer=\u7f16\u7801\u8f6c\u6362 about=\u5173\u4e8e symmetricBlock=\u5bf9\u79f0\u52a0\u5bc6(block) symmetricStream=\u5bf9\u79f0\u52a0\u5bc6(Stream) -asymmetric= \u975e\u5bf9\u79f0\u52a0\u5bc6(RSA) +asymmetric= \u975e\u5bf9\u79f0\u52a0\u5bc6 encrypt=\u52a0\u5bc6 decrypt=\u89e3\u5bc6 fileMode=\u6587\u4ef6\u6a21\u5f0f