Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.bouncycastle.crypto.ec;
 
 
this does your basic ElGamal encryption algorithm using EC
public class ECElGamalEncryptor
    implements ECEncryptor
    private ECPublicKeyParameters key;
    private SecureRandom          random;

    
initialise the encryptor.

Parameters:
param the necessary EC key parameters.
    public void init(
        CipherParameters    param)
    {
        if (param instanceof ParametersWithRandom)
        {
            ParametersWithRandom    p = (ParametersWithRandom)param;
            if (!(p.getParameters() instanceof ECPublicKeyParameters))
            {
                throw new IllegalArgumentException("ECPublicKeyParameters are required for encryption.");
            }
            this. = (ECPublicKeyParameters)p.getParameters();
            this. = p.getRandom();
        }
        else
        {
            if (!(param instanceof ECPublicKeyParameters))
            {
                throw new IllegalArgumentException("ECPublicKeyParameters are required for encryption.");
            }
            this. = (ECPublicKeyParameters)param;
            this. = new SecureRandom();
        }
    }

    
Process a single EC point using the basic ElGamal algorithm.

Parameters:
point the EC point to process.
Returns:
the result of the Elgamal process.
    public ECPair encrypt(ECPoint point)
    {
        if ( == null)
        {
            throw new IllegalStateException("ECElGamalEncryptor not initialised");
        }
        ECDomainParameters ec = .getParameters();
        BigInteger k = ECUtil.generateK(ec.getN(), );
        ECMultiplier basePointMultiplier = createBasePointMultiplier();
        ECPoint[] gamma_phi = new ECPoint[]{
            basePointMultiplier.multiply(ec.getG(), k),
            .getQ().multiply(k).add(point)
        };
        ec.getCurve().normalizeAll(gamma_phi);
        return new ECPair(gamma_phi[0], gamma_phi[1]);
    }
    {
        return new FixedPointCombMultiplier();
    }
New to GrepCode? Check out our FAQ X