Esempio n. 1
0
        /// <summary>
        ///   Create a shared secret between this key and another.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public byte[] GenerateSharedSecret(EphermalKey other)
        {
            var agreement = AgreementUtilities.GetBasicAgreement("ECDH");

            agreement.Init(privateKey);
            return(agreement
                   .CalculateAgreement(other.publicKey)
                   .ToByteArrayUnsigned());
        }
Esempio n. 2
0
        /// <summary>
        ///   Create a shared secret between this key and another.
        /// </summary>
        /// <param name="other">
        ///   Another ephermal key.
        /// </param>
        /// <returns>
        ///   The shared secret as a byte array.
        /// </returns>
        /// <remarks>
        ///   Uses the ECDH agreement algorithm to generate the shared secet.
        /// </remarks>
        public byte[] GenerateSharedSecret(EphermalKey other)
        {
            var agreement = AgreementUtilities.GetBasicAgreement("ECDH");

            agreement.Init(privateKey);
            var secret = agreement.CalculateAgreement(other.publicKey);

            return(BigIntegers.AsUnsignedByteArray(agreement.GetFieldSize(), secret));
        }
Esempio n. 3
0
        public void SharedSecret()
        {
            var curve = "P-256";
            var alice = EphermalKey.Generate(curve);
            var bob   = EphermalKey.Generate(curve);

            var aliceSecret = alice.GenerateSharedSecret(bob);
            var bobSecret   = bob.GenerateSharedSecret(alice);

            CollectionAssert.AreEqual(aliceSecret, bobSecret);
            Assert.AreEqual(32, aliceSecret.Length);
        }