*/
public static SubjectPublicKeyInfo createSubjectPublicKeyInfo(AsymmetricKeyParameter publicKey) throws IOException
{
if (publicKey instanceof RSAKeyParameters)
{
RSAKeyParameters pub = (RSAKeyParameters)publicKey;
return new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(pub.getModulus(), pub.getExponent()));
}
else if (publicKey instanceof DSAPublicKeyParameters)
{
DSAPublicKeyParameters pub = (DSAPublicKeyParameters)publicKey;
return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa), new ASN1Integer(pub.getY()));
}
else if (publicKey instanceof ECPublicKeyParameters)
{
ECPublicKeyParameters pub = (ECPublicKeyParameters)publicKey;
ECDomainParameters domainParams = pub.getParameters();
ASN1Encodable params;
// TODO: need to handle named curves
if (domainParams == null)
{
params = new X962Parameters(DERNull.INSTANCE); // Implicitly CA
}
else
{
X9ECParameters ecP = new X9ECParameters(
domainParams.getCurve(),
domainParams.getG(),
domainParams.getN(),
domainParams.getH(),
domainParams.getSeed());
params = new X962Parameters(ecP);
}
ASN1OctetString p = (ASN1OctetString)new X9ECPoint(pub.getQ()).toASN1Primitive();
return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_ecPublicKey, params), p.getOctets());
}
else
{