Esempio n. 1
0
        /// <summary>
        /// Generate new Keys from seed
        /// </summary>
        /// <param name="seed"></param>
        /// <returns></returns>
        public static Keys Generate(byte[] seed)
        {
            if (seed == null)
            {
                seed = PrivateBox.RandomBytes(32);
            }

            Ed25519 ed25519 = new Ed25519();

            ed25519.FromSeed(seed);
            var secretKey = ed25519.GetPrivateKey();
            var publicKey = ed25519.GetPublicKey();

            var _public  = Convert.ToBase64String(publicKey) + ".ed25519";
            var _private = Convert.ToBase64String(secretKey) + ".ed25519";

            var keys = new Keys
            {
                Curve   = "ed25519",
                Public  = _public,
                Private = _private,
                ID      = "@" + _public,
            };

            return(keys);
        }
Esempio n. 2
0
        public void TestSeededKeys()
        {
            var k1 = Keys.Generate(PrivateBox.RandomBytes(32));
            var k2 = Keys.Generate(PrivateBox.RandomBytes(32));

            Assert.IsTrue(k1 != k2);
        }
Esempio n. 3
0
        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);
            }
        }