Skip to content

Commit

Permalink
feat(app): 非对称加密算法位数选择
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed Apr 18, 2022
1 parent 1e560a9 commit f5597d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
32 changes: 22 additions & 10 deletions app/src/main/kotlin/me/leon/view/AsymmetricCryptoView.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Number> by singleAssign()
lateinit var taInput: TextArea
lateinit var taKey: TextArea
lateinit var taOutput: TextArea
Expand All @@ -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"
Expand All @@ -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()

Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/Messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/Messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5597d2

Please sign in to comment.