public byte[] Create(int n, int max, byte[] pk) { var a = new byte[n][]; a[0] = pk; for (int i = 1; i < n; i++) { a[i] = PublicKeyBox.GenerateKeyPair().PublicKey; } return(PrivateBox.Encrypt(content, a, max)); }
public static string Box(object msg, byte[][] recipientsPublicKey) { var _msg = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(msg)); var _box = new List <byte[]>(); foreach (var recPubKey in recipientsPublicKey) { _box.Add(Sodium.PublicKeyAuth.ConvertEd25519PublicKeyToCurve25519PublicKey(recPubKey)); } var boxed = PrivateBox.Encrypt(_msg, _box); return(Convert.ToBase64String(boxed) + ".box"); }
public void TestSimple() { var msg = "hello there!"; var pubKeys = new byte[][] { alice.PublicKey, bob.PublicKey }; var prvKeys = new byte[][] { alice.PrivateKey, bob.PrivateKey }; var ctxt = PrivateBox.Encrypt(msg, pubKeys); foreach (var sk in prvKeys) { var txt = System.Text.Encoding.UTF8.GetString(PrivateBox.Decrypt(ctxt, sk)); Assert.AreNotSame(msg, txt); } }