derodevil
derodevil

Reputation: 1071

ElGamal signature not verified

I want to implement an ElGamal encryption from this link https://csharp.hotexamples.com/examples/Portable.Licensing.Security.Cryptography.ElGamal/ElGamalKeyStruct/-/php-elgamalkeystruct-class-examples.html

This is what I have tried so far and have no luck

string lic = "abcdefghijklmnopqrstuvwxyz";
byte[] licenseKey = Encoding.UTF8.GetBytes(lic);

ElGamalKeyStruct key = new ElGamalKeyStruct();
key.P = new BigInteger(123567890);
key.G = new BigInteger(1234567890);
key.Y = new BigInteger(1234567890);
key.X = new BigInteger(0); //zero

byte[] signature = CreateSignature(licenseKey, key);
bool verified = VerifySignature(licenseKey, signature, key);

The VerifySignature always returns false.

Upvotes: 0

Views: 275

Answers (1)

xanatos
xanatos

Reputation: 111810

P must be prime. See here (that is the ebook from which the code you use was taken):

Create a random prime number, p. This number is the ElGamal "modulus." The number of bits required to represent p is the size of the public key, so that if p is represented using 1024 bits, then the key created by following the protocol is a 1024-bit key. We will select 607 as our example value.

If you look in the text then there is code to generate El Gamal keys (the CreateKeyPair() method)

Upvotes: 1

Related Questions