sandergroen
Elixir/Erlang equivalent of Ruby OpenSSL
Hi everyone,
I like to know how to how to implement the following Ruby code in Elixir. I guess that I need to look in the Erlang crypto reference but I can’t figure out how to translate the code to Elixir/Erlang.
group = OpenSSL::PKey::EC::Group.new("prime256v1")
key = OpenSSL::PKey::EC.new(group)
pk_bn = OpenSSL::BN.new(pk_bytes, 2)
pk = OpenSSL::PKey::EC::Point.new(group, pk_bn)
I already found how to generate the key.
:crypto.generate_key(:ecdh, :prime256v1)
But how to create the public key bignum (pk_bn) and the public key (pk)?
ps the pk_bytes variable is passed in as a parameter.
Most Liked
voltone
So if I understand correctly, pk_bytes is a raw ECC public key without a curve identity, just a point. The curve is hardcoded to prime256v1.
In that case you should be able to verify a signature like this:
public_key = {{:ECPoint, pk_bytes}, {:namedCurve, :prime256v1}}
:public_key.verify(message, :sha256, signature, public_key)
sandergroen
It took a while before I finally was able to test this but it works like a charm. Thanks Voltone!
jeremyjh
Sorry I don’t know exactly what that Ruby code is doing, but probably the app you are looking for is :public_key:
cmkarlsson
I don’t think you will find the same crypto primitives to do what you want directly from erlang/elixir. The ruby OpenSSL seems to be almost a one-to-one wrapper with OpenSSL whereas the erlang crypto NIF provides a higher abstraction.
The question is what you are trying to achieve? If the code was a function, what is the expected in and out parameters? From the look of the code above you have an incoming parameter pk_bytes (what is pk_bytes?). What do you want to return?







