⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extendedjcersapublickey.java

📁 JAVA做的J2EE下CA认证系统 基于EJB开发
💻 JAVA
字号:
package se.anatom.ejbca.ca.caadmin;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.math.BigInteger;import java.security.interfaces.RSAPublicKey;import java.security.spec.RSAPublicKeySpec;import org.bouncycastle.asn1.ASN1Sequence;import org.bouncycastle.asn1.DERNull;import org.bouncycastle.asn1.DEROutputStream;import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;import org.bouncycastle.asn1.x509.AlgorithmIdentifier;import org.bouncycastle.asn1.x509.RSAPublicKeyStructure;import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;import org.bouncycastle.crypto.params.RSAKeyParameters;public class ExtendedJCERSAPublicKey    implements RSAPublicKey{    private BigInteger modulus;    private BigInteger publicExponent;    ExtendedJCERSAPublicKey(        RSAKeyParameters key)    {        this.modulus = key.getModulus();        this.publicExponent = key.getExponent();    }    ExtendedJCERSAPublicKey(        RSAPublicKeySpec spec)    {        this.modulus = spec.getModulus();        this.publicExponent = spec.getPublicExponent();    }    ExtendedJCERSAPublicKey(        RSAPublicKey key)    {        this.modulus = key.getModulus();        this.publicExponent = key.getPublicExponent();    }    ExtendedJCERSAPublicKey(        SubjectPublicKeyInfo    info)    {        try        {            RSAPublicKeyStructure   pubKey = new RSAPublicKeyStructure((ASN1Sequence)info.getPublicKey());            this.modulus = pubKey.getModulus();            this.publicExponent = pubKey.getPublicExponent();        }        catch (IOException e)        {            throw new IllegalArgumentException("invalid info structure in RSA public key");        }    }    /**     * return the modulus.     *     * @return the modulus.     */    public BigInteger getModulus()    {        return modulus;    }    /**     * return the public exponent.     *     * @return the public exponent.     */    public BigInteger getPublicExponent()    {        return publicExponent;    }    public String getAlgorithm()    {        return "RSA";    }    public String getFormat()    {        return "X.509";    }    public byte[] getEncoded()    {        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();        DEROutputStream         dOut = new DEROutputStream(bOut);        SubjectPublicKeyInfo    info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()), new RSAPublicKeyStructure(getModulus(), getPublicExponent()).getDERObject());        try        {            dOut.writeObject(info);            dOut.close();        }        catch (IOException e)        {            throw new RuntimeException("Error encoding RSA public key");        }        return bOut.toByteArray();    }    public boolean equals(Object o)    {        if ( !(o instanceof RSAPublicKey) )        {            return false;        }        if ( o == this )        {            return true;        }        RSAPublicKey key = (RSAPublicKey)o;        return getModulus().equals(key.getModulus())            && getPublicExponent().equals(key.getPublicExponent());    }    public String toString()    {        StringBuffer    buf = new StringBuffer();        String          nl = System.getProperty("line.separator");        buf.append("RSA Public Key" + nl);        buf.append("            modulus: " + this.getModulus().toString(16) + nl);        buf.append("    public exponent: " + this.getPublicExponent().toString(16) + nl);        return buf.toString();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -