Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error:06000066:public key routines:OPENSSL_internal:DECODE_ERROR #183

Open
akabisdev opened this issue Dec 23, 2024 · 2 comments
Open

error:06000066:public key routines:OPENSSL_internal:DECODE_ERROR #183

akabisdev opened this issue Dec 23, 2024 · 2 comments

Comments

@akabisdev
Copy link

akabisdev commented Dec 23, 2024

Hello,

I am trying to use the following code snippet, i am trying to use this for mobile device

var publicKey = """
-----BEGIN PUBLIC KEY-----
MMKCASI......xxxxxxxx
-----END PUBLIC KEY-----
""";
var keyData = PemCodec(PemLabel.publicKey).decode(publicKey);

 var key = await RsaOaepPublicKey.importSpkiKey(
        keyData,
        Hash.sha256,
      );


I am getting the following exception :
FormatException: error:06000066:public key routines:OPENSSL_internal:DECODE_ERROR

Any suggestion if i missed anything or anything wrong in the approach?

@HamdaanAliQuatil
Copy link
Collaborator

Hey @akabisdev

The issue likely lies in the format of your public key.
Could you please share the steps you took to generate this key.
Or could you run your key through the ASN.1 JavaScript decoder and share the entire link.

For some context; the public key we feed to importSpkiKey needs to be an RSA key in the SPKI format.
The DECODE_ERROR suggests that this might not be the case for this snippet.

Could you try generating the private key and then deriving the public key using OpenSSL:

$ openssl genpkey -algorithm RSA -out pvtk.pem -pkeyopt rsa_keygen_bits:2048
$ openssl pkey -in pvtk.pem -pubout -out pubk.pem

Make sure the value passed to the -algorithm flag is RSA. The resulting key in the file pubk.pem should solve your issue.

Just for caution, could you also verify if your key began with -----BEGIN RSA PUBLIC KEY----- and you manually replaced the inner content of the PEM block?

I've created a test public key in the SPKI format where this issue does not exist, you may find it in this Gist. Here is the ASN.1 Decoding for the same. This may help!

@akabisdev
Copy link
Author

akabisdev commented Jan 6, 2025

Hello @HamdaanAliQuatil,

Actually, the public key i get it from server.. as it is working for web app, in web they are using angular, and using window.crypto.subtle.importKey, i thought to replicate the similar logic on mobile app, but got this error.. Upon investigation, i found, for mobile app, package ffi was used from lib/src/impl_ffi/impl_ffi.rsaoaep.dart,
Image

and not the js package, i.e lib/src/impl_js/impl_js.rsaoaep.dart
Image

So for now, we had made some workaround for this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants