Bouncy Castle Ed25519密钥对的有效OID,用于生成X509Certificate



我使用BouncyCastle库生成x509Certificate,我能够成功生成基于RSA密钥对的证书,但无法使用Ed25519密钥对生成证书。

签名算法SHA256WithEd25519的字符串值似乎不是BouncyCastle中的有效OID。

public static X509Certificate GenerateCertificate(string subject, bool isNotRSA)
{
X509V3CertificateGenerator x509V3CertificateGenerator = new X509V3CertificateGenerator();
X509Name x509Name = new X509Name(subject);
BigInteger bigInteger = BigInteger.ProbablePrime(120, new Random());
x509V3CertificateGenerator.SetSerialNumber(bigInteger);
x509V3CertificateGenerator.SetSubjectDN(x509Name);
x509V3CertificateGenerator.SetIssuerDN(x509Name);
x509V3CertificateGenerator.SetNotAfter(DateTime.UtcNow.AddMonths(10));
x509V3CertificateGenerator.SetNotBefore(DateTime.UtcNow);
AsymmetricCipherKeyPair asymmetricCipherKeyPair = null;
string signatureAlgorithm = string.Empty;
if (isNotRSA)
{
Ed25519KeyPairGenerator ed25519KeyPairGenerator = new Ed25519KeyPairGenerator();
ed25519KeyPairGenerator.Init(new Ed25519KeyGenerationParameters(new SecureRandom()));
asymmetricCipherKeyPair = ed25519KeyPairGenerator.GenerateKeyPair();
signatureAlgorithm = "SHA256WithEd25519";
}
else
{
RsaKeyPairGenerator rsaKeyPairGenerator = new RsaKeyPairGenerator();
rsaKeyPairGenerator.Init(new KeyGenerationParameters(new SecureRandom(new CryptoApiRandomGenerator()), 2048));
asymmetricCipherKeyPair = rsaKeyPairGenerator.GenerateKeyPair();
signatureAlgorithm = "SHA256WithRSA";
}
x509V3CertificateGenerator.SetPublicKey(asymmetricCipherKeyPair.Public);
ISignatureFactory signatureFactory = new Asn1SignatureFactory(signatureAlgorithm, asymmetricCipherKeyPair.Private, new SecureRandom(new CryptoApiRandomGenerator()));
X509Certificate x509Certificate = x509V3CertificateGenerator.Generate(signatureFactory);
return x509Certificate;
}

BouncyCastle库中Ed25519密钥对的有效OID是什么?

签名算法应该是"Ed25519";。

BouncyCastle测试代码提供了出色的指针

最新更新