bishen28

bishen28

Hello guys i am stuck at an issue please help me :pray: :pray: :pray:

for the biometric authentication in my app, from front-end i am getting public key, signature.

for generating key pair, front end using this library → [https://www.npmjs.com/package/react-native-biometrics?activeTab=readme]
and this algorithms → Algorithmic used by above library

example
like i am getting following public key and signature form front end
public_key : MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdBu6w2Var6TJHT8TQ1WdDpMu4VzSrDRP8DjY0WI9ddZvQSvjTdUQ9qm3fyZufZpmhPXfjkmg+f/cbJh+m+Zzhf093bcqVVnmEl+an/FTPMaOy2jfYNbxwZDuYCUxJzewGDa74vXCYB2sPgqZikf3UlhI0ZPO8tbdhleGoiQXOcXloAELQ+ebQ6MDBr+QDqNedPW+hLultTClH56v88Tp85PT6HWnPjVQUAWR7QeL+U8mFZOQALBruQvqfB3BwromhTkTB5XtCy1WCGBtzs21CTok4+pWp5QM/E3IUv1B8dtZDqjMIyGhUnM7pFmgL58UYV1unhyMH/cM+ffzlJWIQIDAQAB

Signature : it is encryption of text = "1675256878678"

DQ6vLV4cRAMcCkpT0MTMHPUc8IoMvcckhjY9Fyirq/zX1Ej851g+IojotyPMqSFKbRqrpE3F2OTI717fcAxFRMCFYlcuf1mYjniCJtGTkxTE6m6GNy+ApX5ssUSb3pZajXcLw/YnKvnbiYtsnL0mFgZ27krrp8ZxEf9iDFBJRZW7JVxjaeGqe5jIN64+NODgR+OvMvHPLpNjKIrZleXwQwbOpWE1q9EIhWmApc2bDdUFeaa5RtGOLI9WNkitkhW/Dsk5FNiZOW7oo85IE65cMJ09XTKHCUmYQnhwtdKibKK84koKXELvBat9/aWe+GBdQJQa6mNFfEPnvcmpXDu3tQ==

in the backend i am using elixir ExPublicKey
so the issue that, the public key i am getting from the front end is not getting load as
the public key object type, something like that

{:ok, public_key} = ExPublicKey.loads(public_key)
iex(64)> ExPublicKey.loads(public_key)
{:error, "invalid argument"}

the desired results should be like this

iex(67)> {:ok, public_key} = ExPublicKey.loads(public_key)
{:ok, #ExPublicKey.RSAPublicKey<
   fingerprint_sha256=                                                                                                   bc                                                                                                         
     31
     a4
     6b
     51
     67
     68
     b2
     63
     60
     66
     73
     39
     ad
     c8
     66
     1e
     07
     9d
     0c
     02
     e6
     31
     23
     16
     9d
     a3
     78
     4a
     04
     ef
     e8>}

{ok, "1675256878678"} = ExPublicKey.decrypt_public(params.signature, public_key, [])

Help me out here. or any alternative solution in elixir for the above encryption/decryption

Showing Posts 1 to 5

jerdew

jerdew

If the public_key is not formatted as a PEM you may need to use ExPublicKey.pem_encode first before you use ExPublicKey.loads

bishen28

bishen28 OP

iex(79)> public_key = 
...(79)> "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdBu6w2Var6TJHT8TQ1WdDpMu4VzSrDRP8DjY0WI9ddZvQSvjTdUQ9qm3fyZufZpmhPXfjkmg+f/cbJh+m+Zzhf093bcqVVnmEl+an/FTPMaOy2jfYNbxwZDuYCUxJzewGDa74vXCYB2sPgqZikf3UlhI0ZPO8tbdhleGoiQXOcXloAELQ+ebQ6MDBr+QDqNedPW+hLultTClH56v88Tp85PT6HWnPjVQUAWR7QeL+U8mFZOQALBruQvqfB3BwromhTkTB5XtCy1WCGBtzs21CTok4+pWp5QM/E3IUv1B8dtZDqjMIyGhUnM7pFmgL58UYV1unhyMH/cM+ffzlJWIQIDAQAB"
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdBu6w2Var6TJHT8TQ1WdDpMu4VzSrDRP8DjY0WI9ddZvQSvjTdUQ9qm3fyZufZpmhPXfjkmg+f/cbJh+m+Zzhf093bcqVVnmEl+an/FTPMaOy2jfYNbxwZDuYCUxJzewGDa74vXCYB2sPgqZikf3UlhI0ZPO8tbdhleGoiQXOcXloAELQ+ebQ6MDBr+QDqNedPW+hLultTClH56v88Tp85PT6HWnPjVQUAWR7QeL+U8mFZOQALBruQvqfB3BwromhTkTB5XtCy1WCGBtzs21CTok4+pWp5QM/E3IUv1B8dtZDqjMIyGhUnM7pFmgL58UYV1unhyMH/cM+ffzlJWIQIDAQAB"


iex(80)> ExPublicKey.pem_encode(public_key)


** (FunctionClauseError) no function clause matching in ExPublicKey.pem_encode/1    
    
    The following arguments were given to ExPublicKey.pem_encode/1:
    
        # 1
        "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdBu6w2Var6TJHT8TQ1WdDpMu4VzSrDRP8DjY0WI9ddZvQSvjTdUQ9qm3fyZufZpmhPXfjkmg+f/cbJh+m+Zzhf093bcqVVnmEl+an/FTPMaOy2jfYNbxwZDuYCUxJzewGDa74vXCYB2sPgqZikf3UlhI0ZPO8tbdhleGoiQXOcXloAELQ+ebQ6MDBr+QDqNedPW+hLultTClH56v88Tp85PT6HWnPjVQUAWR7QeL+U8mFZOQALBruQvqfB3BwromhTkTB5XtCy1WCGBtzs21CTok4+pWp5QM/E3IUv1B8dtZDqjMIyGhUnM7pFmgL58UYV1unhyMH/cM+ffzlJWIQIDAQAB"
    
    Attempted function clauses (showing 2 out of 2):
    
        def pem_encode(key = %ExPublicKey.RSAPrivateKey{})
        def pem_encode(key = %ExPublicKey.RSAPublicKey{})
    
    (ex_crypto 0.10.0) lib/ex_public_key.ex:316: ExPublicKey.pem_encode/1
jerdew

jerdew

That looks like a helpful error message at least, look at the ExPublicKey.RSAPublicKey module, perhaps decode_der?. Also, you’ll probably want to Base.decode64 the key you have, because these functions likely want it in a raw binary format.

Also might be a useful function here: public_key — OTP 29.0.2 (public_key 1.21.2)

Keep trying and search for examples that do work that you can get a hint from.

al2o3cr

al2o3cr

I was able to parse that string into an RSAPublicKey with:

iex(7)> {:ok, public_key} = pk_in |> Base.decode64!() |> ExPublicKey.RSAPublicKey.decode_der()
{:ok, #ExPublicKey.RSAPublicKey<
   fingerprint_sha256=
     39
     9f
     25
     36
     c0
     04
     e8
     10
     d7
     fa
     a8
     bb
     c2
     90
     49
     34
     c5
     c9
     32
     9c
     74
     b1
     1b
     62
     11
     d9
     29
     a3
     12
     2b
     98
     f4>}

which produces a plausible public key (the exponent is 65537) but with a different fingerprint…

It does validate the supplied signature, though:

pk_in = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdBu6w2Var6TJHT8TQ1WdDpMu4VzSrDRP8DjY0WI9ddZvQSvjTdUQ9qm3fyZufZpmhPXfjkmg+f/cbJh+m+Zzhf093bcqVVnmEl+an/FTPMaOy2jfYNbxwZDuYCUxJzewGDa74vXCYB2sPgqZikf3UlhI0ZPO8tbdhleGoiQXOcXloAELQ+ebQ6MDBr+QDqNedPW+hLultTClH56v88Tp85PT6HWnPjVQUAWR7QeL+U8mFZOQALBruQvqfB3BwromhTkTB5XtCy1WCGBtzs21CTok4+pWp5QM/E3IUv1B8dtZDqjMIyGhUnM7pFmgL58UYV1unhyMH/cM+ffzlJWIQIDAQAB"
text = "1675256878678"
signature = "DQ6vLV4cRAMcCkpT0MTMHPUc8IoMvcckhjY9Fyirq/zX1Ej851g+IojotyPMqSFKbRqrpE3F2OTI717fcAxFRMCFYlcuf1mYjniCJtGTkxTE6m6GNy+ApX5ssUSb3pZajXcLw/YnKvnbiYtsnL0mFgZ27krrp8ZxEf9iDFBJRZW7JVxjaeGqe5jIN64+NODgR+OvMvHPLpNjKIrZleXwQwbOpWE1q9EIhWmApc2bDdUFeaa5RtGOLI9WNkitkhW/Dsk5FNiZOW7oo85IE65cMJ09XTKHCUmYQnhwtdKibKK84koKXELvBat9/aWe+GBdQJQa6mNFfEPnvcmpXDu3tQ=="

{:ok, public_key} = pk_in |> Base.decode64!() |> ExPublicKey.RSAPublicKey.decode_der()

{:ok, valid?} = ExPublicKey.verify(text, Base64.decode64!(signature), public_key)
bishen28

bishen28 OP

ok working but one typo here, Thanks

Base.decode64!(signature)

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
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
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
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

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews