https://github.com/andrei-markeev/resty.eddsa
Signing with Ed25519 algorithm in Openresty
https://github.com/andrei-markeev/resty.eddsa
Last synced: 12 months ago
JSON representation
Signing with Ed25519 algorithm in Openresty
- Host: GitHub
- URL: https://github.com/andrei-markeev/resty.eddsa
- Owner: andrei-markeev
- Created: 2022-10-17T18:14:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-18T15:43:31.000Z (over 3 years ago)
- Last Synced: 2025-01-30T06:41:34.741Z (over 1 year ago)
- Language: Lua
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Signing with Ed25519 algorithm in Openresty
This module provides FFI interface to create signatures using EdDSA Ed25519 algorithm. It uses openssl to do the signing. Openresty's `ngx_http_lua_ffi_decode_base64` function is used for decoding private key from base64.
### How to use
Copy file `lib/resty/signEd25519.lua` to the `resty` folder under `lualib`, e.g. `/usr/local/openresty/site/lualib/resty`.
Use in your code like this:
```lua
local eddsa = require("resty.eddsa")
-- private key in base64
local keyInBase64 = "123456789+abcdefghijklmnopqrstuvwxyz+123450="
eddsa.signEd25519(keyInBase64, "message to sign")
```
**NB!** The key should be in RAW format, so e.g. if you have a PEM file (you can generate one using command `openssl genpkey -algorithm ed25519 -outform PEM -out private_key.pem`), you would need to do something like this:
```console
$ openssl pkey -in private_key.pem -noout -text | sed 1,2d | tr -d '\n\r :' | xxd -r -p | base64
```
### TypescriptToLua users:
Install from NPM:
```bash
npm i resty.eddsa
```
Then use from TS like this:
```ts
import {signEd25519} from "resty.eddsa"
signEd25519(privateKeyInBase64, "message to sign");
```