How do to encrypte file like image in Phoenix

I want to encrypte files like image and video in elixir using rsa-public-key.

{:ok, binary} = ExPublicKey.encrypt_public(binary, rsa_public_key)
binary is byte array
how is it possible?

Sorry for being off-topic, but why not use aes-256 (or 128), which would be much more efficient?


As for you question, what’s ExPublicKey, is it a library? Can you give us a link? Is it something you’ve written yourself, can you provide some source code then? Otherwise, it’s a black box, to me, at least …

binary is byte array

Do you mean binary as a variable name? Then which one, you have two variables named binary in your code snippet.

According to the docs exactly like this. What’s the error you get when you try it?

One generally does not encrypt data with asymmetrical crypto like RSA. If you want to use a public key to share data with the owner of the associated private key, generate a random symmetrical key, encrypt the key with RSA and the data with the symmetrical key (e.g. AES).

No offense, but you may want to consult with someone who has some background in crypto, and/or use a well established protocol/library that does exactly what you want to do (instead of giving you primitive building blocks). There’s far too many ways to shoot yourself in the foot when rolling your own.

2 Likes

ExpublicKey not libary, it is function of ExCrypto https://hexdocs.pm/ex_crypto/readme.html#using-expublickey.
binary is expression in below:
{:ok, binary} = File.read(path)
I want encrypte file with using expublickey, it possible?

As I already said, as I read the docs, your example should work already or give you an error, if the latter, can you please post the error? The problem with the docs is, they just give you the function head and no description, so you have to check by trial and error or read the code of the library used. I can’t currently do either as I’m on my daily commute and my train is on the hold because there are people on the tracks…

Also I have to say, even though the library seems to be currently under active development, I hadn’t used it at all, as it is not idiomatic by claiming 3 or more “namespaces”. Also especially when working with crypto related stuff, documentation is important, and that one is missing in your library of choice.

Still, the fact that this isn’t the best idea to use for encryption still holds.

1 Like