retgoat
Hello,
I have a PEM certificate issued for my CSR: my-cert.crt, my private key: private key
I can create a PKCS7 file with that command
openssl smime -sign \
-nodetach \
-in test.txt \
-out signed_data \
-outform PEM \
-signer my-cert.crt \
-inkey private key
My question is: how can I create the same in elixir?
I can sign the file in openssl like that:
openssl dgst -sha256 -sign $privatekey -out /tmp/$filename.sha256 $filename
openssl base64 -in /tmp/$filename.sha256 -out signature.sha256
and verify the signature in elixir:
{:ok, signature} = File.read!("signature.sha256") |> Base.decode64(ignore: :whitespace)
pub = File.read!("my-cert.crt") |> X509.Certificate.from_pem! |> X509.Certificate.public_key
data = File.read!("test.txt")
:public_key.verify(data, :sha256, signature, pub)
true
But I need to create PKCS7 file.
I’m not good at cryptography and maybe lacking some base knowledge ¯_(ツ)_/¯. Sorry for maybe dump question.
Thank you for your help!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
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
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Marked As Solved- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
voltone
Well… OTP’s
:public_keydoes include the ASN.1 definitions for PKCS#7, but it does not offer any higher-level API for working with those data structures.Here’s a little something I put together that will generate output similar to your OpenSSL example:
At this point it only supports RSA and SHA-1. The certificate needs to be passed in as a
Certificaterecord, rather than anOTPCertificaterecord. So if you useX509.Certificate.from_pemto read it, make sure to pass:Certificateas the second argument.You can convert the output to DER format using
:public_key.der_encode(:ContentInfo, ci), or to PEM format with:public_key.pem_entry_encode(:ContentInfo, ci) |> List.wrap() |> :public_key.pem_encode().Also Liked
voltone
As for encryption, this seems to work…
retgoat
@voltone, you’re my hero! Thank you so much!
Last Post!
mtodescato
Ok I was missing the part of the content of the asn1_OPENTYPE of being already a der encoded object.
Since the SigningCertificateV2 is not defined in public_key I need to create the .asn1 files and use those to encode it to der, seems reasonable.
Thank you for your help.