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

org.bouncycastle.bcpg.RSAPublicBCPGKey Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for the OpenPGP Protocol. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.

There is a newer version: 2.0.9
Show newest version
package org.bouncycastle.bcpg;

import java.math.BigInteger;
import java.io.*;

/**
 * base class for an RSA Public Key.
 */
public class RSAPublicBCPGKey 
    extends BCPGObject implements BCPGKey 
{
    MPInteger    n;
    MPInteger    e;
    
    /**
     * Construct an RSA public key from the passed in stream.
     * 
     * @param in
     * @throws IOException
     */
    public RSAPublicBCPGKey(
        BCPGInputStream    in)
        throws IOException
    {
        this.n = new MPInteger(in);
        this.e = new MPInteger(in);
    }

    /**
     * 
     * @param n the modulus
     * @param e the public exponent
     */
    public RSAPublicBCPGKey(
        BigInteger    n,
        BigInteger    e)
    {
        this.n = new MPInteger(n);
        this.e = new MPInteger(e);
    }
    
    public BigInteger getPublicExponent()
    {
        return e.getValue();
    }
    
    public BigInteger getModulus()
    {
        return n.getValue();
    }
    
    /**
     *  return "PGP"
     * 
     * @see org.bouncycastle.bcpg.BCPGKey#getFormat()
     */
    public String getFormat() 
    {
        return "PGP";
    }

    /**
     * return the standard PGP encoding of the key.
     * 
     * @see org.bouncycastle.bcpg.BCPGKey#getEncoded()
     */
    public byte[] getEncoded() 
    {
        try
        {
            return super.getEncoded();
        }
        catch (IOException e)
        {
            return null;
        }
    }
    
    public void encode(
        BCPGOutputStream    out)
        throws IOException
    {
        out.writeObject(n);
        out.writeObject(e);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy