com.unbound.provider.RSAKeyPairGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
package com.unbound.provider;
import com.dyadicsec.provider.KeyGenSpec;
import com.dyadicsec.provider.KeyParameters;
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
public final class RSAKeyPairGenerator extends KeyPairGeneratorSpi
{
private Partition partition;
private int bitSize;
private KeyParameters keyParameter = null;
RSAKeyPairGenerator(Partition partition)
{
this.partition = partition;
}
// --------------------- interface -----------------
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException
{
if (!(params instanceof KeyGenSpec)) throw new InvalidAlgorithmParameterException("Not supported algorithm parameter spec");
keyParameter = ((KeyGenSpec)params).getKeyParams();
initialize(((KeyGenSpec)params).getBitSize(), random);
}
@Override
public void initialize(int bitSize, SecureRandom random)
{
this.bitSize = bitSize;
if (bitSize!=2048 && bitSize!=3072 && bitSize!=4096) throw new InvalidParameterException("Unsupported RSA key size " + bitSize);
}
@Override
public KeyPair generateKeyPair()
{
UBRSAPrivateKey key = new UBRSAPrivateKey(partition);
try
{
key.generate(keyParameter, bitSize, null);
}
catch (Exception e)
{
throw new ProviderException(e);
}
return new KeyPair(key.pub, key);
}
}