summaryrefslogtreecommitdiff
path: root/examples/vrfy.sig
diff options
context:
space:
mode:
authorwilliam <william@25tandclement.com>2013-12-09 21:26:39 -0800
committerwilliam <william@25tandclement.com>2013-12-09 21:26:39 -0800
commite3ec2e4f949267ca48fe9fe983dd00f41010c2a8 (patch)
tree744fc7d57d94e044699c0f7ece7cb47cb56cfaff /examples/vrfy.sig
parent9db41e05d9a00eb906b530b38bcaaa068d40c88b (diff)
downloadluaossl-e3ec2e4f949267ca48fe9fe983dd00f41010c2a8.tar.gz
luaossl-e3ec2e4f949267ca48fe9fe983dd00f41010c2a8.tar.bz2
luaossl-e3ec2e4f949267ca48fe9fe983dd00f41010c2a8.zip
copy over our examples/
Diffstat (limited to 'examples/vrfy.sig')
-rwxr-xr-xexamples/vrfy.sig35
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
6local pubkey = require"openssl.pubkey"
7local digest = require"openssl.digest"
8
9-- generate a public/private key pair
10local 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).
14local data = digest.new"ecdsa-with-SHA1"
15data:update(... or "hello world")
16
17-- generate a signature for our data
18local sig = key:sign(data)
19
20-- to prove verification works, instantiate a new object holding just
21-- the public key
22local pub = pubkey.new(key:toPEM"public")
23
24-- a utility routine to output our signature
25local 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
31end
32
33print("okay", pub:verify(sig, data))
34print("type", pub:type())
35print("sig", tohex(sig))