diff options
author | william <william@25tandclement.com> | 2013-12-09 21:26:39 -0800 |
---|---|---|
committer | william <william@25tandclement.com> | 2013-12-09 21:26:39 -0800 |
commit | e3ec2e4f949267ca48fe9fe983dd00f41010c2a8 (patch) | |
tree | 744fc7d57d94e044699c0f7ece7cb47cb56cfaff /examples/vrfy.sig | |
parent | 9db41e05d9a00eb906b530b38bcaaa068d40c88b (diff) | |
download | luaossl-e3ec2e4f949267ca48fe9fe983dd00f41010c2a8.tar.gz luaossl-e3ec2e4f949267ca48fe9fe983dd00f41010c2a8.tar.bz2 luaossl-e3ec2e4f949267ca48fe9fe983dd00f41010c2a8.zip |
copy over our examples/
Diffstat (limited to 'examples/vrfy.sig')
-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)) | ||