📄 jcersapublickey.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: JCERSAPublicKey.java
package org.bouncycastle.jce.provider;
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.*;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.*;
import org.bouncycastle.crypto.params.RSAKeyParameters;
public class JCERSAPublicKey
implements RSAPublicKey
{
private BigInteger modulus;
private BigInteger publicExponent;
JCERSAPublicKey(RSAKeyParameters key)
{
modulus = key.getModulus();
publicExponent = key.getExponent();
}
JCERSAPublicKey(RSAPublicKeySpec spec)
{
modulus = spec.getModulus();
publicExponent = spec.getPublicExponent();
}
JCERSAPublicKey(RSAPublicKey key)
{
modulus = key.getModulus();
publicExponent = key.getPublicExponent();
}
JCERSAPublicKey(SubjectPublicKeyInfo info)
{
try
{
RSAPublicKeyStructure pubKey = new RSAPublicKeyStructure((ASN1Sequence)info.getPublicKey());
modulus = pubKey.getModulus();
publicExponent = pubKey.getPublicExponent();
}
catch (IOException e)
{
throw new IllegalArgumentException("invalid info structure in RSA public key");
}
}
public BigInteger getModulus()
{
return modulus;
}
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;
} else
{
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((new StringBuilder()).append("RSA Public Key").append(nl).toString());
buf.append((new StringBuilder()).append(" modulus: ").append(getModulus().toString(16)).append(nl).toString());
buf.append((new StringBuilder()).append(" public exponent: ").append(getPublicExponent().toString(16)).append(nl).toString());
return buf.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -