You might have to describe what you are seeing as a "difference". Regards, David On 16/7/22 08:04, felix.quin...@yahoo.com wrote:
I'm having trouble reading the private key generated by openssl and bouncy castle. They are different and I don't know why. The key generated with openssl ,'openssl req -x509 -newkey rsa:2048 -keyout autosign.key -out autosign.cer -days 365 -nodes' I have to read it with RsaPrivateCrtKeyParameters and the one generated with bouncy castle with AsymmetricCipherKeyPair and I can't find the difference between them. I'm also not sure that the way to convert a certificate and key to a p12 file is correct. using (StreamReader streamReader = File.OpenText(archivoKey)) { Org.BouncyCastle.OpenSsl.PemReader pemReader; pemReader = new Org.BouncyCastle.OpenSsl.PemReader(streamReader, new PasswordFinder(clave)); /*AsymmetricCipherKeyPair keyPair; keyPair = (AsymmetricCipherKeyPair)pemReader.ReadObject();*/ RsaPrivateCrtKeyParameters keyPair; keyPair = (RsaPrivateCrtKeyParameters)pemReader.ReadObject(); streamReader.Close(); X509CertificateEntry[] chain = new X509CertificateEntry[1]; X509CertificateParser x509CertificateParser = new X509CertificateParser(); X509Certificate cert = x509CertificateParser.ReadCertificate(File.ReadAllBytes(archivoCsr)); IDictionary bagAttr = new Hashtable(); bagAttr.Add(PkcsObjectIdentifiers.Pkcs9AtFriendlyName.Id, new DerBmpString(noExtension)); /*bagAttr.Add(PkcsObjectIdentifiers.Pkcs9AtLocalKeyID.Id, new SubjectKeyIdentifierStructure(pubKey));*/ chain[0] = new X509CertificateEntry(cert, bagAttr); bagAttr = new Hashtable(); Pkcs12Store store = new Pkcs12StoreBuilder().Build(); store.SetKeyEntry(noExtension, new AsymmetricKeyEntry(keyPair, bagAttr), chain); FileStream fOut = File.Create(archivep12)); store.Save(fOut, clave.ToCharArray(), new SecureRandom()); fOut.Close(); }