public void encryptDecryptTo(int n) { var msg = PrivateBox.RandomBytes(1024); var keys = new System.Collections.Generic.List <KeyPair>(); for (int i = 0; i < keys.Count; i++) { keys[i] = PublicKeyBox.GenerateKeyPair(); } var ctxt = PrivateBox.Multibox(msg, keys.Select(x => x.PublicKey).ToArray(), n); // a recipient key may open the message. foreach (var key in keys) { Assert.AreEqual(PrivateBox.MultiboxOpen(ctxt, key.PrivateKey, n), msg); } }
public void TestErrorsWhenMaxIsMoreThan255OrLessThan1() { var msg = "hello there!"; var ctxt = PrivateBox.Multibox(msg, new byte[][] { alice.PublicKey, bob.PublicKey }); var pk = alice.PublicKey; var sk = alice.PrivateKey; Assert.Catch(new TestDelegate(delegate { PrivateBox.Multibox(msg, new byte[][] { pk, pk, pk, pk }, -1); })); Assert.Catch(new TestDelegate(delegate { PrivateBox.MultiboxOpen(ctxt, sk, 256); })); Assert.Pass(); }
public static Newtonsoft.Json.Linq.JObject Unbox(string boxed, byte[] privateKey) { if (privateKey == null) { return(null); } var _boxed = Utilities.ToByteArray(boxed); var sk = Sodium.PublicKeyAuth.ConvertEd25519SecretKeyToCurve25519SecretKey(privateKey); try { var msg = PrivateBox.MultiboxOpen(_boxed, sk); return(JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(Encoding.UTF8.GetString(msg))); } catch { return(null); } }