Node.js

SmartField SDK for Node.js

Decrypt SmartField encrypted data with Node.js. Works with Express. Tested on port 3333.

Installation

npm install @smartfield-dev/server

Initialize

const sf = require('@smartfield-dev/server'); await sf.init(); app.use(sf.middleware());

This generates RSA-2048 keys locally. Keys are stored in .smartfield/ and never sent anywhere.

Decrypt

const password = await sf.decrypt(req.body.password);

That's it. The encrypted payload from the browser is decrypted server-side. Only your server has the private key.

How It Works

  1. Browser: SmartField encrypts user input with AES-256-GCM
  2. Browser: AES key is wrapped with your server's RSA-2048 public key
  3. Network: Encrypted payload sent to your Node.js server
  4. Server: RSA private key unwraps the AES key
  5. Server: AES key decrypts the data
  6. Server: Plaintext available only here

Frontend Setup

<script src="https://cdn.smartfield.dev/v1/smartfield.js"></script> <smart-field type="password" encrypt-key="/api/sf-key" placeholder="password"></smart-field>

Encryption Details

Related Pages

Full Documentation