Share2Me

Back to Articles
Security

How Secure File Transfer Works: Ephemeral Keys & AES-GCM-256

July 2, 2026
Share

In an era of frequent server data breaches, uploading sensitive files to cloud drives is a security risk. Secure file transfer requires end-to-end encryption (E2EE), ensuring only the sender and receiver hold the decryption keys. In this article, we explain the cryptographic mathematics behind secure file transfers, demonstrating how Share2Me (Share 2 Me / Share To / Share2) derives keys locally using ECDH key exchanges and encrypts payload packets using AES-GCM-256.

1. Ephemeral Key Exchange: The Math of ECDH

Symmetric encryption requires both parties to share a single secret key. Exposing this key during transmission defeats the purpose of encryption. Elliptic Curve Diffie-Hellman (ECDH) solves this. By using public-key cryptography on the NIST P-256 elliptic curve, both browsers generate temporary private keys and derive public keys. They swap public keys over the socket. By combining their private key with the peer's public key, both derive the exact same shared secret. An eavesdropper monitoring the exchange only sees the public keys, making it mathematically impossible to calculate the shared secret.

  • NIST P-256: A widely trusted curve providing strong security with low computational overhead.
  • Shared Secret Derivation: Derived locally in browser memory, never transmitted over the wire.
  • Forward Secrecy: Keys are ephemeral and discarded after the session, protecting past transfers.

2. Authenticated Encryption with AES-GCM-256

Once the shared secret is derived, it is fed into a Key Derivation Function (HKDF) to generate a 256-bit AES key. The browser then encrypts the files using AES-GCM-256 (Advanced Encryption Standard with Galois/Counter Mode). Unlike older CBC modes, GCM is an 'Authenticated Encryption' algorithm. It produces both the ciphertext and an authentication tag. If a malicious node alters even a single bit of the file during transit, the decryption process will detect the mismatch and halt immediately, protecting users from man-in-the-middle attacks.

  • Confidentiality: Data remains unreadable to third parties.
  • Authenticity: Validates that the sender is the author of the payload.
  • Integrity: Detects any data corruption or tampering instantly.

3. Web Crypto API: Hardware-Accelerated Browser Security

Historically, web applications executed cryptography using slow JavaScript libraries (like Crypto.js), which caused browser tabs to freeze. Modern browsers solve this with the native Web Crypto API. Written in optimized C++ and integrated directly into the browser engine, the Web Crypto API accesses hardware-accelerated CPU instructions (AES-NI). This allows browser-native encryption of large files at near-native write speeds, keeping performance smooth and secure.

Conclusion

By combining browser-native Web Crypto API, ephemeral ECDH key exchange, and AES-GCM-256 authentication, modern P2P networks guarantee absolute data security. Share2Me is designed around these protocols, ensuring your files never fall into the wrong hands.