8 ms·
It's all in libsodium. For example, below a pynacl API usage fragment, abridged from their docs [1]. No crypto parameters or nonces or authentication are expose
by FabHK 7y ago
It's all in libsodium. For example, below a pynacl API usage fragment, abridged from their docs [1]. No crypto parameters or nonces or authentication are exposed. Modern crypto is really relatively easy to use.
(What's never trivial is key management, how do you get Alice's public key, but that's hard with any sort of public key cryptography.)
# Generate Bob's private key, which must be kept secret
skbob = PrivateKey.generate()
# Bob's public key, and similarly for Alice...
pkbob = skbob.public_key
# Bob wishes to send Alice an encrypted message so Bob must make a Box with
# his private key and Alice's public key
bob_box = Box(skbob, pkalice)
# This is our message to send (binary blob of data)
message = b"Kill all humans"
# Encrypt our message
encrypted = bob_box.encrypt(message)
[1] https://pynacl.readthedocs.io/en/stable/public/ https://pynacl.readthedocs.io/en/stable/public/
- lvh 7y agoFWIW the cool API here that PyNaCl exposes (but not every libsodium impl) is automatically selecting the nonce for you.
- FabHK 7y agoIndeed, the documentation mentions it and does expose it, but I abridged it out to show how trouble-free the default implementation is.
- jj11837 7y agoThe last thing you should start with is "it's all in lobsodium". You didn't understand the point. "how do you get Alice's public key, but that's hard with any sort of public key cryptography." That sentence makes absolutely no sense, it's a public key, why would it be hard to send? The problem is people are like "just use product X, you don't have to understand it". Marketing wanketeering is what makes crypto more difficult in the first place. No one gives a shit about shipping your product. "Just use libsoduium" is an easy way to add to the problem.
- adrianN 7y agoThe hard part about getting Alice's key is making sure that it's actually Alice's.
- michael-ax 7y agothanks from me and probably 10k+ more people for saying that :)
- 0xDEFC0DE 7y agoI think most would just hardcode it or a reference to it (API call to secrets management) because setting up PKI for a single encrypted channel feature is pretty demanding and also more chances to get something wrong.
- adrianN 7y agoIf you can do that it seems to me like you could just use symmetric crypto, but I'm really not an expert on this.
- IanCal 7y agoIf I'm following this thread properly, the important difference here is that with symmetric crypto you'd also have to make sure nobody else saw the key. With public keys, it doesn't matter if someone snooped.
- quelltext 7y agoI thought Diffie-Hellman key exchange covers the snooping part, at least over the channel. I guess it doesn't protect against something attacking and snooping on your machine though.
- tptacek 7y agoDH by itself protects against passive attackers, but most "snoopers" aren't passive. To securely exchange keys over an untrusted network, you usually want an authenticated key exchange, which is more complicated than DH.