Search in sources :

Example 1 with ElGamalKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.ElGamalKeyGenerationParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof ElGamalParameterSpec) && !(params instanceof DHParameterSpec)) {
        throw new InvalidAlgorithmParameterException("parameter object not a DHParameterSpec or an ElGamalParameterSpec");
    }
    if (params instanceof ElGamalParameterSpec) {
        ElGamalParameterSpec elParams = (ElGamalParameterSpec) params;
        param = new ElGamalKeyGenerationParameters(random, new ElGamalParameters(elParams.getP(), elParams.getG()));
    } else {
        DHParameterSpec dhParams = (DHParameterSpec) params;
        param = new ElGamalKeyGenerationParameters(random, new ElGamalParameters(dhParams.getP(), dhParams.getG(), dhParams.getL()));
    }
    engine.init(param);
    initialised = true;
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ElGamalParameters(com.github.zhenwei.core.crypto.params.ElGamalParameters) ElGamalKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ElGamalKeyGenerationParameters) DHParameterSpec(javax.crypto.spec.DHParameterSpec) ElGamalParameterSpec(com.github.zhenwei.provider.jce.spec.ElGamalParameterSpec)

Example 2 with ElGamalKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.ElGamalKeyGenerationParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        DHParameterSpec dhParams = WeGooProvider.CONFIGURATION.getDHDefaultParameters(strength);
        if (dhParams != null) {
            param = new ElGamalKeyGenerationParameters(random, new ElGamalParameters(dhParams.getP(), dhParams.getG(), dhParams.getL()));
        } else {
            ElGamalParametersGenerator pGen = new ElGamalParametersGenerator();
            pGen.init(strength, certainty, random);
            param = new ElGamalKeyGenerationParameters(random, pGen.generateParameters());
        }
        engine.init(param);
        initialised = true;
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    ElGamalPublicKeyParameters pub = (ElGamalPublicKeyParameters) pair.getPublic();
    ElGamalPrivateKeyParameters priv = (ElGamalPrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCElGamalPublicKey(pub), new BCElGamalPrivateKey(priv));
}
Also used : KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) ElGamalParameters(com.github.zhenwei.core.crypto.params.ElGamalParameters) ElGamalPrivateKeyParameters(com.github.zhenwei.core.crypto.params.ElGamalPrivateKeyParameters) ElGamalKeyGenerationParameters(com.github.zhenwei.core.crypto.params.ElGamalKeyGenerationParameters) DHParameterSpec(javax.crypto.spec.DHParameterSpec) ElGamalPublicKeyParameters(com.github.zhenwei.core.crypto.params.ElGamalPublicKeyParameters) ElGamalParametersGenerator(com.github.zhenwei.core.crypto.generators.ElGamalParametersGenerator) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Aggregations

ElGamalKeyGenerationParameters (com.github.zhenwei.core.crypto.params.ElGamalKeyGenerationParameters)2 ElGamalParameters (com.github.zhenwei.core.crypto.params.ElGamalParameters)2 DHParameterSpec (javax.crypto.spec.DHParameterSpec)2 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1 ElGamalParametersGenerator (com.github.zhenwei.core.crypto.generators.ElGamalParametersGenerator)1 ElGamalPrivateKeyParameters (com.github.zhenwei.core.crypto.params.ElGamalPrivateKeyParameters)1 ElGamalPublicKeyParameters (com.github.zhenwei.core.crypto.params.ElGamalPublicKeyParameters)1 ElGamalParameterSpec (com.github.zhenwei.provider.jce.spec.ElGamalParameterSpec)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyPair (java.security.KeyPair)1