bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
237 stars 122 forks source link

Working with PEM files #51

Closed penhorwood closed 3 years ago

penhorwood commented 4 years ago

Is Point Castle able to read and write RSA PEM files? I need to turn a PEM file created with Bouncy Castle back into a RSA Public Key.

penhorwood commented 4 years ago

I can use this class in Bouncy Castle to turn a byte array back into a Public Key. org.bouncycastle.crypto.util.PublicKeyFactory.createKey( base64 decoded byteArray )

My understanding is a PEM file is just a formatted base64 encoded byteArray.

hoylen commented 3 years ago

Try using the ssh_key package.

Ephenodrom commented 3 years ago

@penhorwood Also take a look at my Basic Utils package.

https://github.com/Ephenodrom/Dart-Basic-Utils#cryptoutils

penhorwood commented 3 years ago

I found the time to work on this project again. @Ephenodrom I tried the Basic-Utils package but there is something wrong with the BigInt decoding of PEM ANS.1 files. I always get an error. I did find a package 'package:rsa_pkcs/rsa_pkcs.dart' that works for parsing PKCS #1 formatted PEM files. But I also need to create PEM files in PKCS #1 or PKCS #8 format. It would be great if these features were just added to Pointy Castle.

My main objective is to be able to exchange RSA signed encrypted documents between a server running Bouncy Castle with a phone running Pointy Castle.

Ephenodrom commented 3 years ago

@penhorwood can you provide an example PEM where the parsing creates an error ? The PEM parsing should work fine, due to it is heavily used by myself. I also parsed over 50k x509 certificates issued by DigiCert without a problem.

penhorwood commented 3 years ago

@Ephenodrom I will see if I can provide an example. I maybe have also done something to cause it to fail. My knowledge of Dart is very limited.

penhorwood commented 3 years ago

@Ephenodrom - Well I was indeed wrong on the crashing. I had used the wrong method for converting from PEM 8 to Public Key.