In the case of the AsymmetricCipherKeyPair it's because it's possible to
build the public key from the private key data as well, they're just
slightly different ways of looking at the same data.
Regards,
David
On 16/7/22 22:45, felix.quin...@yahoo.com wrote:
The difference is that I have to read them into different types of variables.
One in AsymmetricCipherKeyPair and the other in RsaPrivateCrtKeyParameters,
when I check using 'openssl rsa -check -in autosign.key' both give me the same
result.
On Saturday, July 16, 2022, 12:31:58 AM GMT-4, David Hook
<d...@cryptoworkshop.com> wrote:
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();
}