コード例 #1
0
ファイル: Test_Benchmark.cs プロジェクト: Cinorid/PrivateBox
        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));
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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);
            }
        }