dersar00
Hello!
I want to encrypt some string with my own key, how I can do it? I prefer to do it with some encryption technology that I can use to decrypt this in my js frontend.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
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
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
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
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
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
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
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
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Maybe
dersar00
Nice, but how I can get
encryptedas a string, because I need to send it to my frontend?voltone
This approach has several weaknesses:
Instead of building an encryption scheme from primitives, consider using high-level API such as JWE or Plug.Crypto (plug_crypto | Hex)
dersar00
And what about if I want to run a bash command inside my app and use stdout, for example I have a command
echo 'foo' | openssl aes-256-cbc -a -salt -k oneand I got a stdout result what I need, but how I can run this command usingSystem.cmd? I have troubles with that.NobbZ
Either do it correct and use a
Portand send messages to it, or do it one-shot:System.cmd("sh", ["echo 'foo' | openssl aes-256-cbc -a -salt -k one"])or something…voltone
This improves on the earlier proposal in that it uses CBC, but it still relies on a weak KDF. If you need to use a password (rather than a binary key) you are going to have to bring in a package that implements a strong KDF. You can do the rest with
:cryptoAPIs, no need to shell out to OpenSSL.Another package that could help is pbcs | Hex, but its documentation is very minimal.
wyrdforge
I’m currently struggling to get some similar setup up and running and just don’t get, howto do things.
First and foremost, we don’t do this for server security, but to fulfill GDPR regulations, just to be sure.
We are authenticating PPPoE users by freeradius via CHAP. Basically this means, the customer sends a hash value created from password and a challenge. The radius server has to keep a cleartext password for this to work. For GDPR, we would rather persist the user password aes encrypted. So we now deliver the cleartext password by the SQL query: AES_DECRYPT(UNHEX(value), ‘ThisIsMySecretAesKey’)
So what I try to do is the opposite HEX(AES_ECNRYPT(‘Password’, ‘ThisIsMySecretAesKey’)).
Looking at the (scarce) examples, :aes_ecb boils down to a simple: :crypto.block_encrypt(:aes_ecb, “Key”, “Pass”), but this didn’t work out:
Leads to:
As this seems to work for several people, maybe someone has some insights, why not in my case.
The above example works, but I assume, padding the strings would not yield the same result with the sql decrypt query?
cmkarlsson
An AES key must be 16 bytes long. Payload must be a in blocks of even 16 bytes but if using aes_ecb you should not encrypt more than 1 block (16 bytes). It is not secure to do so.
If using another crypto mode, such as aes_cbc you must pad it so that the payload is evenly divided by the block size but if you pad you must authenticate the crypto otherwise it is not secure. (See padding oracle)
And if you authenticate the crypto please make sure that you use a constant time compare when checking the authentication otherwise this can be utilized to crack the crypto.
Alternatively use a crypto with authentication such as AES-GCM.
EDIT:
I’ve had a look at the AES_ENCRYPT in MySQl (which I assume you are using?). They do pad the string but they don’t mention which padding algorithm, iv or what type of aes mode they are using but from some stackoverflow post it seems like they are using AES-ECB, padded with PKCS#5.
wyrdforge
Ah thanks, I think, MySQL then does this implicitly, while using :crypto, I have to care for this myself.
The real problem is, that (normally), a radius server just awaits a cleartext password from database and in most cases it is realized this way (so, this is more snakeoil to calm our CEOs, security wise
). As far as I know, MySQL does not support ctr based modes, like gcm , so we really seem to be stuck with ecb here.
We could use PAP, with stronger encryption, but unfortunately, PPPoE users would then be forced to send cleartext password while logging in as UDP
Personally, taking into account the possibility, that after an outage, around >20k Users want to log in again as fast as possible, I’d be more comfortable by cleartext password and avoid the encryption overhead for a weak encryption.
EDIT:
That was just my experience. I also di not find a lot of infos, how MySQL does this. ECB was the best, I could get from searching. How the padding is implicitly done is not documented too well.
cmkarlsson
Yes, you’d have to reverse engineer whatever MySQL is doing. Seems like later versions of MySQL do support different crypto modes (such as cbc).
I just tried and MySQL uses AES-ECB-128 by default. I can decrypt like this:
and then decrypt it in elixir
But I don’t know what padding they use if the key is not 16 bytes. Somewhere it is claimed to be 0 padded but I couldn’t get it to work.
All in all, from a security point of view this feels very dodgy. From storing the passwords in the database (instead of a hash, even if encrypted) to the algorithms used.