Crowdhailer
Creator of Raxx
I’m experimenting with using the web crypto API. and want to verify signatures from the browser in Elixir (or erlang, so far I have used only modules that are also available in erlang).
The steps in the browser are:
- generate a key pair.
- export public-key in PEM format
- Sign message
- Base64 encode the signature
- Send the PEM public-key and encoded signature to the backend
The steps to verify on the backend:
- decode PEM
- decode signature
- use
:public_key.verify
The exact code I run is available in this gist.
This files can be used by copy pasting sign.js into the browser console and verify.ex into an iex session.
Doing this the verify function will return false.
I have tried several variations of how I encode/decode. I do need these encode steps because I eventually want to send the signature in the authorization header of a request.
Any help would be greatly appreciated.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
voltone
The JS API returns a ‘raw’ signature, whereas OTP’s
:public_keyAPI expects a DER-encoded signature.Try this:
voltone
To clean up that code, here’s a module that can help convert from raw format to DER format using
:public_key:I might add it to x509 at some point…
Crowdhailer
Thanks for this. So to use the functions bellow I would use?
Also does the
:public_keymodule not expect DER encoding for RSA keys? My original code seams to work for rsa signaturesExadra37
I am curious to know what are you trying to achieve with this approach of sending the signature in the
authorizationheader of a request?voltone
Correct
An RSA signature is just a single integer, which is simply encoded as a binary by all implementations. An ECDSA signature consists of two integers. Some implementations wrap those in an ASN.1 ‘Sequence’ and others just concatenate them (which may require zero-padding of the smaller of the two, to remove ambiguity about where to split).
Crowdhailer
Just some experiments at the moment, but in general i’m looking at alternatives to passwords
Exadra37
Client side generated secrets can be reverse engineered in mobile apps, that ship their code obfuscated in binaries, and in the web is even more easy to reverse engineer this process, thus anything generated programmatically in the client side cannot be trusted for authentication purposes.
Crowdhailer
What about
Crypto.getRandomValues()?Exadra37
Sorry I was not meaning the code used to generate the secret… What I was trying to say is that any secret generated in the client side can be reused by an automated script to access the backend as the genuine web app or mobile app.
Another approach is that the automated script can use the same code of your app to generate the authorization secret, thus your backend will trust in requests from automated bots, when you want it to only trust in requests from your genuine web app or mobile app.
Crowdhailer
Ahh I think I see. I don’t think I have any problems with people using their own client to access my API, if they want to go to that effort