I'm generating a CSR programmatically in Xamarin Android as follows
var subject = new X509Name(subjectName);
// Generate the key Value Pair, which in our case is a public Key
var random = new SecureRandom();
const int strength = 2048;
var keyGenerationParameters = new KeyGenerationParameters(random, strength);
var keyPairGenerator = new RsaKeyPairGenerator();
keyPairGenerator.Init(keyGenerationParameters);
AsymmetricCipherKeyPair subjectKeyPair = keyPairGenerator.GenerateKeyPair();
Pkcs10CertificationRequest csr = new Pkcs10CertificationRequest("SHA256WITHRSA", subject, subjectKeyPair.Public, null, subjectKeyPair.Private);
which works fine, but I can't find how to add an extension. There are multiple guides for java that use Pkcs10CertificationRequestFactory, which doesn't exist in the c# version. I assume this was changed to make it more .net style and less java, but I can't figure out where that functionality went. I can generate the X509Extension like
X509ExtensionsGenerator extensionsGenerator = new X509ExtensionsGenerator();
Asn1EncodableVector vec = new Asn1EncodableVector();
Asn1EncodableVector v = new Asn1EncodableVector();
v.Add(new DerObjectIdentifier("1.3.6.1.4.1.311.20.2.3"));
v.Add(new DerTaggedObject(true, 0, new DerUtf8String("devuser@dvam.local"))
);
Asn1Object gn = new DerTaggedObject(false, 0, new DerSequence(v));
vec.Add(gn);
extensionsGenerator.AddExtension(X509Extensions.SubjectAlternativeName, true, new
DerSequence(vec));
var ext = extensionsGenerator.Generate();
but this is where in java you would invoke the factory. The Pkcs10CertificationRequest constructor takes in a Asn1Set attributes, which I assume would be where you'd pass it, but Asn1Set.GetInstance doesn't work on any of the above objects.