Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,41 @@
|
||||
module main
|
||||
|
||||
import encoding.hex
|
||||
import encoding.base64
|
||||
import crypto.ed25519
|
||||
|
||||
// adapted from https://asecuritysite.com/signatures/ed25519
|
||||
fn main() {
|
||||
msg := 'Hello Girl'
|
||||
|
||||
publ, priv := ed25519.generate_key()!
|
||||
|
||||
m := msg.bytes()
|
||||
|
||||
sig := ed25519.sign(priv, m)!
|
||||
|
||||
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)}')
|
||||
|
||||
rtn := ed25519.verify(publ, m, sig)!
|
||||
|
||||
if rtn {
|
||||
println('Signature verified :${rtn}')
|
||||
} else {
|
||||
println('signature does not verify :${!rtn}')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user