Inheritance: ElGamalKeyParameters
Ejemplo n.º 1
0
        public void TestElGamal()
        {

                BigInteger ELGamalParaG = new BigInteger(Base64.Decode("QAZPRcsH8kHVKS5065R1Xy6QtsPvDkmDZtPuq18EJkvLrCIZivE/m5puQp3/VKJrG7dKgz4NBGpONp3HT+Cn/g=="));
                BigInteger ELGamalParaP = new BigInteger(Base64.Decode("AKXmAwgkudDLI/Yxk6wk3APn+mSjX5QSyDwpchmegSIi1ZNC0Jb+IbxjroKNhRTBKjtv4/JTXtJS6IqaZv9uKes="));
                BigInteger ELGamalPubY = new BigInteger(Base64.Decode("AJ/gXuZuCA2X044otNkzs8FI36XuFu1L/YHg5cEmDvICTigycRN2E1DnhP+CTqxEqgEqX8rBe5tuGDlkTLwgNqM="));
                BigInteger ELGamalPriv = new BigInteger(Base64.Decode("CqVr+K0TpuJKQnc76MjKhxrJzGr93jnuE3mTpth486Meymt8uWEVAQj1tGc9DTt14F9aV9WIT2oYYbvLJRcwow=="));



                ElGamalParameters elPara = new ElGamalParameters(ELGamalParaP, ELGamalParaG);

                ElGamalPrivateKeyParameters elPriv = new ElGamalPrivateKeyParameters(ELGamalPriv, elPara);
                ElGamalPublicKeyParameters elPub = new ElGamalPublicKeyParameters(ELGamalPubY, elPara);

                SubjectPublicKeyInfo subInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(elPub);
                PrivateKeyInfo privInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(elPriv);

                ElGamalPrivateKeyParameters telPriv = (ElGamalPrivateKeyParameters)PrivateKeyFactory.CreateKey(privInfo);
                ElGamalPublicKeyParameters telPub = (ElGamalPublicKeyParameters)PublicKeyFactory.CreateKey(subInfo);


                             // Console.WriteLine(telPriv.Equals(elPriv));



                Assert.IsTrue(telPriv.Equals(elPriv), "ELGamal Private key to into back to private key.");
                Assert.IsTrue(telPub.Equals(elPub), "ELGamal Public key to into back to private key.");

                Assert.IsTrue(true, "ELGamal Test worked.");

            }
 protected bool Equals(ElGamalPublicKeyParameters other)
 {
     return _y.Equals(other.Y) && base.Equals(other);
 }
Ejemplo n.º 3
0
		public void TestElGamal()
		{
			BigInteger g512 = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
			BigInteger p512 = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);

			ElGamalParameters dhParams = new ElGamalParameters(p512, g512);
			ElGamalKeyGenerationParameters parameters = new ElGamalKeyGenerationParameters(new SecureRandom(), dhParams);         ElGamalKeyPairGenerator kpGen = new ElGamalKeyPairGenerator();

			kpGen.Init(parameters);

			AsymmetricCipherKeyPair pair = kpGen.GenerateKeyPair();
			ElGamalPublicKeyParameters pu1 = (ElGamalPublicKeyParameters)pair.Public;
			ElGamalPrivateKeyParameters pv1 = (ElGamalPrivateKeyParameters)pair.Private;

			ElGamalPublicKeyParameters pu2 = new ElGamalPublicKeyParameters(pu1.Y, pu1.Parameters);
			ElGamalPrivateKeyParameters pv2 = new ElGamalPrivateKeyParameters(pv1.X, pv1.Parameters);
			ElGamalPublicKeyParameters pu3 = new ElGamalPublicKeyParameters(pv1.X, pu1.Parameters);
			ElGamalPrivateKeyParameters pv3 = new ElGamalPrivateKeyParameters(pu1.Y, pu1.Parameters);

			doTest(pu1, pu2, pu3);
			doTest(pv1, pv2, pv3);

			ElGamalParameters pr1 = pu1.Parameters;
			ElGamalParameters pr2 = new ElGamalParameters(pr1.P, pr1.G);
			ElGamalParameters pr3 = new ElGamalParameters(pr1.G, pr1.P);

			doTest(pr1, pr2, pr3);

			pu2 = new ElGamalPublicKeyParameters(pu1.Y, pr2);
			pv2 = new ElGamalPrivateKeyParameters(pv1.X, pr2);

			doTest(pu1, pu2, pu3);
			doTest(pv1, pv2, pv3);

			ElGamalTestKeyParameters k1 = new ElGamalTestKeyParameters(false, null);
			ElGamalTestKeyParameters k2 = new ElGamalTestKeyParameters(false, null);
			ElGamalTestKeyParameters k3 = new ElGamalTestKeyParameters(false, pu1.Parameters);

			doTest(k1, k2, k3);
		}
Ejemplo n.º 4
0
		public void TestInvalidP()
		{
			ElGamalParameters dhParams = new ElGamalParameters(pPgpBogusPSamp, gPgpBogusPSamp, lPgpBogusPSamp);
			ElGamalPublicKeyParameters pu = new ElGamalPublicKeyParameters(yPgpBogusPSamp, dhParams);
			ElGamalPrivateKeyParameters pv = new ElGamalPrivateKeyParameters(xPgpBogusPSamp, dhParams);

			ElGamalEngine e = new ElGamalEngine();

			e.Init(true, pu);

			byte[] message = Hex.Decode("5468697320697320612074657374");

			byte[] pText = message;
			byte[] cText = e.ProcessBlock(pText, 0, pText.Length);

			e.Init(false, pv);

			pText = e.ProcessBlock(cText, 0, cText.Length);

			if (Arrays.AreEqual(message, pText))
			{
				Fail("invalid test failed");
			}
		}
Ejemplo n.º 5
0
 protected bool Equals(
     ElGamalPublicKeyParameters other)
 {
     return(y.Equals(other.y) && base.Equals(other));
 }
Ejemplo n.º 6
0
 protected bool Equals(ElGamalPublicKeyParameters other) =>
 (this.y.Equals(other.y) && base.Equals((ElGamalKeyParameters)other));