Closed batrlatom closed 5 years ago
We do not currently have any plans to add Javascript support.
I think your best bet may we to write a small Python server in something like Django, Flask, or Tornado that can process requests that involve calls into the CrypTen library. Alternatively, you could add Thrift definitions for the relevant CrypTen functions so that you can do RPC. This would allow you to call into CrypTen from Javascript.
We would like to emphasize that CrypTen is not currently a production-ready framework, so we would discourage you from developing real products on top of it.
@lvdmaaten I would like to ask you one question though . I am not sure if I am missing the point entirely. I want the server to compute an operation over two encoded tensors sent from the client. But in the way, that server cannot see what are plain values of tensors. So the client can always trust that his data would not be stolen.
Could you please help me to get to the point?
server code:
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
import torch
import crypten
import jsonify
import pickle
from io import BytesIO
import codecs
crypten.init()
app = Flask(__name__)
socketio = SocketIO(app)
@socketio.on('adition')
def test_message(message):
x_bytes = message['x']
y_bytes = message['y']
x_unpickled = pickle.loads(codecs.decode(x_bytes.encode(), "base64"))
y_unpickled = pickle.loads(codecs.decode(y_bytes.encode(), "base64"))
output = x_unpickled + y_unpickled
print(x_unpickled.get_plain_text())
print(y_unpickled.get_plain_text())
print(output.get_plain_text())
output_bytes = codecs.encode(pickle.dumps(output), "base64").decode()
#print(output_bytes)
emit('output', {'output': output_bytes})
if __name__ == '__main__':
socketio.run(app)
client code:
from socketIO_client import SocketIO, LoggingNamespace
import torch
import crypten
import jsonify
import pickle
from io import BytesIO
import codecs
crypten.init()
with SocketIO('localhost', 5000, LoggingNamespace) as socketIO:
x = torch.tensor([1.0])
y = torch.tensor([2.0])
x_enc = crypten.cryptensor(x) # encrypt
y_enc = crypten.cryptensor(y) # encrypt
x_bytes = codecs.encode(pickle.dumps(x_enc), "base64").decode()
y_bytes = codecs.encode(pickle.dumps(y_enc), "base64").decode()
socketIO.emit('adition', {'x': x_bytes, 'y': y_bytes})
socketIO.wait(seconds=1)
Hi @batrlatom,
The current version of CrypTen supports a secure multiparty computation (MPC) backend. In MPC, the parties are peers and must execute the same code to perform computations. Here, the client could be considered the data source by specifying it using the src
keyword argument. However, the client and server would both execute the same code (i.e. both parties would run something like test_message above). Please refer to Tutorial 1 for an example of how this works, and Tutorial 2 for an example of how to specify data sources.
The notion of a client data provider and server code execution fits more with a homomorphic encryption (HE) backend. This is not currently supported in CrypTen, though we plan to incorporate it into a future release, though we cannot give any explicit timeline for this.
@knottb I see, thank you for the clarification!
Feature
I would like to use crypten with javascript application ( nodejs, vuejs, etc. ). It would be nice to have javascript encryption/decryption. If I would like to use some encrypted web api, I am unable to do it without some python proxy which adds complexity to the real world deployment. Would you think that it would be possible to add some javascript encryptor/decryptor ?
Alternatives
Additional context