Exemplo n.º 1
0
		public byte[] PerformKeyAgreement (ECKeyPair otherPublicKey, int keyDataLength)
		{
			if (otherPublicKey.Q == null) {
				if (otherPublicKey.D == null)
					throw new CryptographicException ();
				otherPublicKey.CreatePublicKeyFromPrivateKey ();
			}
			return PerformKeyAgreement (otherPublicKey.Q, keyDataLength);
		}
Exemplo n.º 2
0
 public byte[] PerformKeyAgreement(ECKeyPair otherPublicKey, int keyDataLength)
 {
     if (otherPublicKey.Q == null)
     {
         if (otherPublicKey.D == null)
         {
             throw new CryptographicException();
         }
         otherPublicKey.CreatePublicKeyFromPrivateKey();
     }
     return(PerformKeyAgreement(otherPublicKey.Q, keyDataLength));
 }
Exemplo n.º 3
0
        public void Test_GEC2()
        {
            ECDomainNames      domainName = ECDomainNames.secp160r1;
            ECDomainParameters domain     = ECDomains.GetDomainParameter(domainName);
            ECIES     ecies     = new ECIES(domainName);
            Number    V_Private = Number.Parse("45FB58A92A17AD4B15101C66E74F277E2B460866", 16);
            ECKeyPair pair      = new ECKeyPair(V_Private, null, domain);

            pair.CreatePublicKeyFromPrivateKey();
            ecies.Parameters._Q = pair._Q;
            byte[] M         = System.Text.Encoding.ASCII.GetBytes("abcdefghijklmnopqrst");
            byte[] k         = Number.Parse("702232148019446860144825009548118511996283736794", 10).ToByteArray(20, false);
            byte[] C         = ecies.Encrypt(M, k);
            byte[] expectedC = new byte[] { 0x02, 0xCE, 0x28, 0x73, 0xE5, 0xBE, 0x44, 0x95, 0x63, 0x39, 0x1F, 0xEB, 0x47, 0xDD, 0xCB, 0xA2, 0xDC, 0x16, 0x37, 0x91, 0x91, 0x71, 0x23, 0xC8, 0x70, 0xA3, 0x1A, 0x81, 0xEA, 0x75, 0x83, 0x29, 0x0D, 0x1B, 0xA1, 0x7B, 0xC8, 0x75, 0x94, 0x35, 0xED, 0x1C, 0xCD, 0xA9, 0xEB, 0x4E, 0xD2, 0x73, 0x60, 0xBE, 0x89, 0x67, 0x29, 0xAD, 0x18, 0x54, 0x93, 0x62, 0x25, 0x91, 0xE5 };
            Assert.AreEqual(expectedC, C, "Encryption");

            ecies = new ECIES(domainName);
            ecies.Parameters._d = V_Private;
            byte[] M2 = ecies.Decrypt(C);
            Assert.AreEqual(M, M2, "Decryption");
        }