Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.jcajce.provider.asymmetric.ecgost;
  
 
 
 public class KeyPairGeneratorSpi
     extends java.security.KeyPairGenerator
 {
     Object ecParams = null;
 
     String algorithm = "ECGOST3410";
     int strength = 239;
     SecureRandom random = null;
     boolean initialised = false;
 
     public KeyPairGeneratorSpi()
     {
         super("ECGOST3410");
     }
 
     public void initialize(
         int strength,
         SecureRandom random)
     {
         this. = strength;
         this. = random;
 
         if ( != null)
         {
             try
             {
                 initialize((ECGenParameterSpec)random);
             }
             catch (InvalidAlgorithmParameterException e)
             {
                 throw new InvalidParameterException("key size not configurable.");
             }
         }
         else
         {
             throw new InvalidParameterException("unknown key size.");
         }
     }
 
     public void initialize(
         AlgorithmParameterSpec params,
         SecureRandom random)
         throws InvalidAlgorithmParameterException
     {
         if (params instanceof ECParameterSpec)
         {
             ECParameterSpec p = (ECParameterSpec)params;
             this. = params;
 
              = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN()), random);
 
             .init();
              = true;
         }
         else if (params instanceof java.security.spec.ECParameterSpec)
         {
             java.security.spec.ECParameterSpec p = (java.security.spec.ECParameterSpec)params;
             this. = params;
 
             ECCurve curve = EC5Util.convertCurve(p.getCurve());
             ECPoint g = EC5Util.convertPoint(curvep.getGenerator(), false);
 
              = new ECKeyGenerationParameters(new ECDomainParameters(curvegp.getOrder(), BigInteger.valueOf(p.getCofactor())), random);
 
             .init();
              = true;
         }
         else if (params instanceof ECGenParameterSpec || params instanceof ECNamedCurveGenParameterSpec)
         {
             String curveName;
 
             if (params instanceof ECGenParameterSpec)
            {
                curveName = ((ECGenParameterSpec)params).getName();
            }
            else
            {
                curveName = ((ECNamedCurveGenParameterSpec)params).getName();
            }
            ECDomainParameters ecP = ECGOST3410NamedCurves.getByName(curveName);
            if (ecP == null)
            {
                throw new InvalidAlgorithmParameterException("unknown curve name: " + curveName);
            }
            this. = new ECNamedCurveSpec(
                curveName,
                ecP.getCurve(),
                ecP.getG(),
                ecP.getN(),
                ecP.getH(),
                ecP.getSeed());
            ECCurve curve = EC5Util.convertCurve(p.getCurve());
            ECPoint g = EC5Util.convertPoint(curvep.getGenerator(), false);
             = new ECKeyGenerationParameters(new ECDomainParameters(curvegp.getOrder(), BigInteger.valueOf(p.getCofactor())), random);
            .init();
             = true;
        }
        else if (params == null && ..getEcImplicitlyCa() != null)
        {
            this. = params;
             = new ECKeyGenerationParameters(new ECDomainParameters(p.getCurve(), p.getG(), p.getN()), random);
            .init();
             = true;
        }
        else if (params == null && ..getEcImplicitlyCa() == null)
        {
            throw new InvalidAlgorithmParameterException("null parameter passed but no implicitCA set");
        }
        else
        {
            throw new InvalidAlgorithmParameterException("parameter object not a ECParameterSpec: " + params.getClass().getName());
        }
    }
    public KeyPair generateKeyPair()
    {
        if (!)
        {
            throw new IllegalStateException("EC Key Pair Generator not initialised");
        }
        ECPublicKeyParameters pub = (ECPublicKeyParameters)pair.getPublic();
        if ( instanceof ECParameterSpec)
        {
            ECParameterSpec p = (ECParameterSpec);
            BCECGOST3410PublicKey pubKey = new BCECGOST3410PublicKey(pubp);
            return new KeyPair(pubKey,
                new BCECGOST3410PrivateKey(privpubKeyp));
        }
        else if ( == null)
        {
            return new KeyPair(new BCECGOST3410PublicKey(pub),
                new BCECGOST3410PrivateKey(priv));
        }
        else
        {
            BCECGOST3410PublicKey pubKey = new BCECGOST3410PublicKey(pubp);
            return new KeyPair(pubKeynew BCECGOST3410PrivateKey(privpubKeyp));
        }
    }
New to GrepCode? Check out our FAQ X