All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.unbound.provider.RSAKeyPairGenerator Maven / Gradle / Ivy

Go to download

This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi

There is a newer version: 42761
Show newest version
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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy