2022-02-15 20:28:14 +01:00
|
|
|
module main
|
|
|
|
|
|
|
|
import encoding.hex
|
|
|
|
import encoding.base64
|
|
|
|
import crypto.ed25519
|
|
|
|
|
|
|
|
// adapted from https://asecuritysite.com/signatures/ed25519
|
|
|
|
fn main() {
|
|
|
|
msg := 'Hello Girl'
|
|
|
|
|
2022-05-13 05:56:21 +02:00
|
|
|
publ, priv := ed25519.generate_key()?
|
2022-02-15 20:28:14 +01:00
|
|
|
|
|
|
|
m := msg.bytes()
|
|
|
|
|
2022-05-13 05:56:21 +02:00
|
|
|
sig := ed25519.sign(priv, m)?
|
2022-02-15 20:28:14 +01:00
|
|
|
|
|
|
|
println('=== Message ===')
|
|
|
|
println('Msg: $msg \nHash: $m')
|
|
|
|
|
|
|
|
println('=== Public key ===')
|
|
|
|
println('Public key (Hex): ${hex.encode(publ)}')
|
|
|
|
println(' Public key (Base64): ${base64.encode(publ)}')
|
|
|
|
|
|
|
|
println('=== Private key ===')
|
|
|
|
println('Private key: $priv.seed().hex()') // priv[0:32]
|
|
|
|
println(' Private key (Base64): ${base64.encode(priv.seed())}') // priv[0:32]
|
|
|
|
println(' Private key (Base64) Full key: ${base64.encode(priv)}')
|
|
|
|
println(' Private key (Full key in Hex): ${hex.encode(priv)}')
|
|
|
|
|
|
|
|
println('=== signature (R,s) ===')
|
|
|
|
println('signature: R=${sig[0..32].hex()} s=${sig[32..64].hex()}')
|
|
|
|
println(' signature (Base64)=${base64.encode(sig)}')
|
|
|
|
|
2022-05-13 05:56:21 +02:00
|
|
|
rtn := ed25519.verify(publ, m, sig)?
|
2022-02-15 20:28:14 +01:00
|
|
|
|
|
|
|
if rtn {
|
|
|
|
println('Signature verified :$rtn')
|
|
|
|
} else {
|
|
|
|
println('signature does not verify :${!rtn}')
|
|
|
|
}
|
|
|
|
}
|