aboutsummaryrefslogtreecommitdiffstats
path: root/examples/vrfy.sig
diff options
context:
space:
mode:
authorLibravatarLibravatar william <william@25tandclement.com> 2013-12-09 21:26:39 -0800
committerLibravatarLibravatar william <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 @@
+#!/usr/local/lua52/bin/lua
+--
+-- Example public-key signature verification.
+--
+
+local pubkey = require"openssl.pubkey"
+local digest = require"openssl.digest"
+
+-- generate a public/private key pair
+local key = pubkey.new{ type = "EC", curve = "prime192v1" }
+
+-- digest our message using an appropriate digest ("ecdsa-with-SHA1" for EC;
+-- "dss1" for DSA; and "sha1", "sha256", etc for RSA).
+local data = digest.new"ecdsa-with-SHA1"
+data:update(... or "hello world")
+
+-- generate a signature for our data
+local sig = key:sign(data)
+
+-- to prove verification works, instantiate a new object holding just
+-- the public key
+local pub = pubkey.new(key:toPEM"public")
+
+-- a utility routine to output our signature
+local function tohex(b)
+ local x = ""
+ for i = 1, #b do
+ x = x .. string.format("%.2x", string.byte(b, i))
+ end
+ return x
+end
+
+print("okay", pub:verify(sig, data))
+print("type", pub:type())
+print("sig", tohex(sig))