0

I recently implement multiple cryptographic schemes. I plan to use Java Bouncy Castle. I found importing the scheme is very easy. My first implementation is the ElGamal encryption. My question is that how to import my generated Big prime number p and order q and use these parameters to generate the key pairs with Bouncy castle.

I found when I use the Bouncy Castle, I can import the name of the scheme and 'BC'. For example, Elgamal encryption.

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ElGamal", "BC");

My question is that how can I get the generator g, order q, and big prime number p from this because other schemes need these parameters.

chaoliu
  • 1
  • 1

1 Answers1

1

You don't 'get' the field parameters, you provide them. Note you only need p and g; although the generator g does (must) have a large prime order q in Z_p^* the ElGamal implementation doesn't use or need that order.

KeyPairGenerator.init with either Bouncy's ElGamalParameterSpec or JCA's DHParameterSpec. JCA doesn't define classes (or algorithms) for ElGamal, but the mathematical fields used are the same as for Diffie-Hellman which it does define, so Bouncy allows you to 'repurpose' the DH classes. (Like Rocky on PAW Patrol: don't lose it, reuse it!)

dave_thompson_085
  • 34,712
  • 6
  • 50
  • 70