diff options
Diffstat (limited to '')
-rwxr-xr-x | examples/vrfy.sig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/vrfy.sig b/examples/vrfy.sig new file mode 100755 index 0000000..94daf43 --- /dev/null +++ b/examples/vrfy.sig | |||
@@ -0,0 +1,35 @@ | |||
1 | #!/usr/local/lua52/bin/lua | ||
2 | -- | ||
3 | -- Example public-key signature verification. | ||
4 | -- | ||
5 | |||
6 | local pubkey = require"openssl.pubkey" | ||
7 | local digest = require"openssl.digest" | ||
8 | |||
9 | -- generate a public/private key pair | ||
10 | local key = pubkey.new{ type = "EC", curve = "prime192v1" } | ||
11 | |||
12 | -- digest our message using an appropriate digest ("ecdsa-with-SHA1" for EC; | ||
13 | -- "dss1" for DSA; and "sha1", "sha256", etc for RSA). | ||
14 | local data = digest.new"ecdsa-with-SHA1" | ||
15 | data:update(... or "hello world") | ||
16 | |||
17 | -- generate a signature for our data | ||
18 | local sig = key:sign(data) | ||
19 | |||
20 | -- to prove verification works, instantiate a new object holding just | ||
21 | -- the public key | ||
22 | local pub = pubkey.new(key:toPEM"public") | ||
23 | |||
24 | -- a utility routine to output our signature | ||
25 | local function tohex(b) | ||
26 | local x = "" | ||
27 | for i = 1, #b do | ||
28 | x = x .. string.format("%.2x", string.byte(b, i)) | ||
29 | end | ||
30 | return x | ||
31 | end | ||
32 | |||
33 | print("okay", pub:verify(sig, data)) | ||
34 | print("type", pub:type()) | ||
35 | print("sig", tohex(sig)) | ||