Ephenodrom / Dart-Basic-Utils

A dart package for many helper methods fitting common situations
MIT License
368 stars 79 forks source link

Crypto: Type 'ASN1Sequence' is not a subtype of type 'ASN1Integer' #108

Open larssn opened 11 months ago

larssn commented 11 months ago

I'm trying to read the following public certificate (pem):

-----BEGIN CERTIFICATE-----
MIIGUjCCBIagAwIBAgIUZLBJrCCkrmubG6GrwvsOlMXxYP4wQQYJKoZIhvcNAQEK
MDSgDzANBglghkgBZQMEAgEFAKEcMBoGCSqGSIb3DQEBCDANBglghkgBZQMEAgEF
AKIDAgEgMFYxLTArBgNVBAMMJERlbiBEYW5za2UgU3RhdCBPQ0VTIHVkc3RlZGVu
ZGUtQ0EgMTEYMBYGA1UECgwPRGVuIERhbnNrZSBTdGF0MQswCQYDVQQGEwJESzAe
Fw0yMzEyMDgxMTIzMTlaFw0yNjEyMDcxMTIzMThaMIGJMRMwEQYDVQQDDAp0aWxs
dHkgUE9TMTcwNQYDVQQFEy5VSTpESy1POkc6OGE1ZTcwOWEtNTEyNi00MDg1LTlh
YzAtYTFiZDI4ZTNkYWY5MRMwEQYDVQQKDAp0aWxsdHkgQXBTMRcwFQYDVQRhDA5O
VFJESy0zMjgyNjU2MzELMAkGA1UEBhMCREswggGiMA0GCSqGSIb3DQEBAQUAA4IB
jwAwggGKAoIBgQC81L+HWHvw07hTbUyj9nlmcU6+TGhtXkJQbfvt4NQF7Ay58ipl
s9mYEex8aTUgVOlmrvwZcyrGUPh6ONd11QNJogk93xsJexvRdCLO0p9HfuwolX/a
LGCJNxsSfRWaxBNb6sdVepDzCIbDAa2YPbdM0h9EMXfjREywBByR69s+onbNYPRt
82eYPcTVVfD2hk/JPsAjPN/6VtOzY0TGnHuD6yHod0IdeuIWzMxYiNeD0k5UKZiW
WKRUKGCwePrZFm0HAjLWdMMKMsg2XSkgOtQ3peALXENEtua60y4wA9nFdvGRWGlF
PHKnq7Y6uhVub0kgunqk8ouUHvE6ssBWDjaLmdYVqRg+BJtzsi93T1tIUE6CP9O5
t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Y8MjKdEj0kUK2dtoyAq9b
SSzqYxr1QYhDZW3CD4IcojArDenCz+rNw5Ll9yv5jZhylkzq5w69NetjDgXkj60N
LfAWCwR0jHtgsvilJ82FnY/Fqei32UoDCIKFjRRiGwLOmS328jOOPpQmS0X2NLGu
ZgndN5R1s9rwHnd7f9LHVNG6Bicr+YXRzu9PRCxZcWFnRV/psAo=
-----END CERTIFICATE-----

It contains a 3072 bit RSA public key.

However when using CryptoUtils.rsaPublicKeyFromPem(myPem); it throws an exception:

I/flutter ( 8208): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
I/flutter ( 8208): The following _CastError was thrown:
I/flutter ( 8208): type 'ASN1Sequence' is not a subtype of type 'ASN1Integer' in type cast
I/flutter ( 8208):
I/flutter ( 8208): When the exception was thrown, this was the stack:
I/flutter ( 8208): #0      CryptoUtils.rsaPublicKeyFromDERBytes   CryptoUtils.dart:541
I/flutter ( 8208): #1      CryptoUtils.rsaPublicKeyFromPem   CryptoUtils.dart:522