Skip to content

Commit

Permalink
feat(app): signature support output hex signed data
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed Apr 24, 2022
1 parent 6c4ba0c commit 763366b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
17 changes: 11 additions & 6 deletions app/src/main/kotlin/me/leon/controller/SignatureController.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.leon.controller

import me.leon.encode.base.base64
import me.leon.encode.base.base64Decode
import me.leon.ext.*
import me.leon.ext.crypto.sign
import me.leon.ext.crypto.verify
Expand All @@ -15,14 +13,15 @@ class SignatureController : Controller() {
pri: String,
msg: String,
inputEncode: String,
outEncode: String,
isSingleLine: Boolean
) =
catch({ it }) {
if (isSingleLine)
msg.lineAction2String {
it.decodeToByteArray(inputEncode).sign(kpAlg, sigAlg, pri).base64()
it.decodeToByteArray(inputEncode).sign(kpAlg, sigAlg, pri).encodeTo(outEncode)
}
else msg.decodeToByteArray(inputEncode).sign(kpAlg, sigAlg, pri).base64()
else msg.decodeToByteArray(inputEncode).sign(kpAlg, sigAlg, pri).encodeTo(outEncode)
}

fun verify(
Expand All @@ -31,19 +30,25 @@ class SignatureController : Controller() {
pub: String,
msg: String,
inputEncode: String,
outEncode: String,
signed: String,
isSingleLine: Boolean
) =
catch({ it }) {
if (isSingleLine)
msg.lineActionIndex { s, i ->
s.decodeToByteArray(inputEncode)
.verify(kpAlg, sigAlg, pub, signed.lineSplit()[i].base64Decode())
.verify(
kpAlg,
sigAlg,
pub,
signed.lineSplit()[i].decodeToByteArray(outEncode)
)
.toString()
}
else
msg.decodeToByteArray(inputEncode)
.verify(kpAlg, sigAlg, pub, signed.base64Decode())
.verify(kpAlg, sigAlg, pub, signed.decodeToByteArray(outEncode))
.toString()
}
}
14 changes: 14 additions & 0 deletions app/src/main/kotlin/me/leon/view/SignatureView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ class SignatureView : Fragment(messages["signVerify"]) {
"${messages["outputLength"]}: ${signText.length} " +
"cost: $timeConsumption ms"
private var inputEncode = "raw"
private var outputEncode = "base64"
private lateinit var tgInput: ToggleGroup
private lateinit var tgOutput: ToggleGroup
private val centerNode = vbox {
addClass(Styles.group)
hbox {
Expand Down Expand Up @@ -233,7 +235,17 @@ class SignatureView : Fragment(messages["signVerify"]) {
}
}
hbox {
addClass(Styles.left)
label(messages["sig"])
tgOutput =
togglegroup {
radiobutton("base64") { isSelected = true }
radiobutton("hex")
selectedToggleProperty().addListener { _, _, newValue ->
outputEncode = newValue.cast<RadioButton>().text
}
}

button(graphic = imageview("/img/copy.png")) { action { signText.copy() } }
}

Expand All @@ -258,6 +270,7 @@ class SignatureView : Fragment(messages["signVerify"]) {
key,
msg,
inputEncode,
outputEncode,
isSingleLine.get()
)
} ui
Expand All @@ -277,6 +290,7 @@ class SignatureView : Fragment(messages["signVerify"]) {
key,
msg,
inputEncode,
outputEncode,
signText,
isSingleLine.get()
)
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 @@ -30,7 +30,7 @@ priSig=Private Key Sign
priEncrypt=Private Key Encrypt
genKeypair=Generate Keypair
pubVerify=Public Key Verify
sig=Signature(base64):
sig=Signature:
outputLength=Output Length
inputLength=Input Length
outputEncoding=Output Encoding:
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 @@ -30,7 +30,7 @@ priSig=Private Key Sign
priEncrypt=Private Key Encrypt
genKeypair=Generate Keypair
pubVerify=Public Key Verify
sig=Signature(base64):
sig=Signature:
outputLength=Output Length
inputLength=Input Length
outputEncoding=Output Encoding:
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 @@ -30,7 +30,7 @@ priSig=\u79c1\u94a5\u7b7e\u540d
priEncrypt=\u79c1\u94a5\u52a0\u5bc6
genKeypair=\u751f\u6210\u516c\u79c1\u94a5
pubVerify=\u516c\u94a5\u9a8c\u7b7e
sig=\u7b7e\u540d(base64):
sig=\u7b7e\u540d:
outputLength=\u8f93\u51fa\u957f\u5ea6
inputLength=\u8f93\u5165\u957f\u5ea6
outputEncoding=\u8f93\u51fa\u7f16\u7801:
Expand Down

0 comments on commit 763366b

Please sign in to comment.