Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.jcajce.provider.asymmetric.dh;
  
  
 
 
 
 public class BCDHPrivateKey
 {
     static final long serialVersionUID = 311058815616901812L;
     
     private BigInteger      x;
 
     private transient DHParameterSpec dhSpec;
     private transient PrivateKeyInfo  info;
 
 
     protected BCDHPrivateKey()
     {
     }
 
     BCDHPrivateKey(
         DHPrivateKey key)
     {
         this. = key.getX();
         this. = key.getParams();
     }
 
     BCDHPrivateKey(
         DHPrivateKeySpec spec)
     {
         this. = spec.getX();
         this. = new DHParameterSpec(spec.getP(), spec.getG());
     }
 
     public BCDHPrivateKey(
         PrivateKeyInfo info)
         throws IOException
     {
         ASN1Sequence    seq = ASN1Sequence.getInstance(info.getPrivateKeyAlgorithm().getParameters());
         ASN1Integer      derX = (ASN1Integer)info.parsePrivateKey();
         ASN1ObjectIdentifier id = info.getPrivateKeyAlgorithm().getAlgorithm();
 
         this. = info;
         this. = derX.getValue();
 
         if (id.equals(.))
         {
             DHParameter params = DHParameter.getInstance(seq);
 
             if (params.getL() != null)
             {
                 this. = new DHParameterSpec(params.getP(), params.getG(), params.getL().intValue());
             }
             else
             {
                 this. = new DHParameterSpec(params.getP(), params.getG());
             }
         }
         else if (id.equals(.))
         {
             DHDomainParameters params = DHDomainParameters.getInstance(seq);
 
             this. = new DHParameterSpec(params.getP().getValue(), params.getG().getValue());
         }
         else
         {
             throw new IllegalArgumentException("unknown algorithm type: " + id);
         }
     }
 
     BCDHPrivateKey(
         DHPrivateKeyParameters params)
     {
         this. = params.getX();
         this. = new DHParameterSpec(params.getParameters().getP(), params.getParameters().getG(), params.getParameters().getL());
    }
    public String getAlgorithm()
    {
        return "DH";
    }

    
return the encoding format we produce in getEncoded().

Returns:
the string "PKCS#8"
    public String getFormat()
    {
        return "PKCS#8";
    }

    
Return a PKCS8 representation of the key. The sequence returned represents a full PrivateKeyInfo object.

Returns:
a PKCS8 representation of the key.
    public byte[] getEncoded()
    {
        try
        {
            if ( != null)
            {
                return .getEncoded(.);
            }
            PrivateKeyInfo          info = new PrivateKeyInfo(new AlgorithmIdentifier(.new DHParameter(.getP(), .getG(), .getL()).toASN1Primitive()), new ASN1Integer(getX()));
            return info.getEncoded(.);
        }
        catch (Exception e)
        {
            return null;
        }
    }
    public DHParameterSpec getParams()
    {
        return ;
    }
    public BigInteger getX()
    {
        return ;
    }
    public boolean equals(
        Object o)
    {
        if (!(o instanceof DHPrivateKey))
        {
            return false;
        }
        DHPrivateKey other = (DHPrivateKey)o;
        return this.getX().equals(other.getX())
            && this.getParams().getG().equals(other.getParams().getG())
            && this.getParams().getP().equals(other.getParams().getP())
            && this.getParams().getL() == other.getParams().getL();
    }
    public int hashCode()
    {
        return this.getX().hashCode() ^ this.getParams().getG().hashCode()
                ^ this.getParams().getP().hashCode() ^ this.getParams().getL();
    }
    public void setBagAttribute(
        ASN1ObjectIdentifier oid,
        ASN1Encodable attribute)
    {
        .setBagAttribute(oidattribute);
    }
        ASN1ObjectIdentifier oid)
    {
        return .getBagAttribute(oid);
    }
    {
        return .getBagAttributeKeys();
    }
    private void readObject(
        ObjectInputStream   in)
        throws IOExceptionClassNotFoundException
    {
        in.defaultReadObject();
        this. = new DHParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject(), in.readInt());
        this. = null;
        this. = new PKCS12BagAttributeCarrierImpl();
    }
    private void writeObject(
        ObjectOutputStream  out)
        throws IOException
    {
        out.defaultWriteObject();
        out.writeObject(.getP());
        out.writeObject(.getG());
        out.writeInt(.getL());
    }
New to GrepCode? Check out our FAQ X