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

Base64 Decoding Failed (asn1ParsingFailed) #256

Open
MarkParker5 opened this issue Jul 21, 2023 · 0 comments
Open

Base64 Decoding Failed (asn1ParsingFailed) #256

MarkParker5 opened this issue Jul 21, 2023 · 0 comments

Comments

@MarkParker5
Copy link

I have the base64-encoded public key

let publicKey = "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxRks1TFBsclEwanpwSnhEN2VWQgpVYTBLVmVDT1o4akFaWVI0T0NWSzVlZlRGMzdHSXBlWmxrUHVVcWJsR2M4akJVMEQrMnVqU29xVUh4d1c2TmRDCklaUjBZblU4dGJNWVoyRTRlVTVzZkdySmdIbm1scEZnYlA4SDZyRWt3emZlQm03NGhkd1dXeFU4WHVtWDdUNVoKRlJHai9lRUp0a3pCMDhkS2hKckJuTTBTRzhscXU0S3k2cmd2cXh0VC9ENmNhN0g4ZVpDV0MzM29PditvSm9ITwpmd3dFRHVJVThncGFrWmNhZWpBTWVWVVdYUStES0s4THo0YmRjUGwzSUJrNFVHdTN5bVRFN2gxb3RQaDBPUUNICm5vUk1QNTdZNmMvVmVYQytmRnZXTy9mUEphUU9MYk9jV0poTFFTVGlFUTJHNzdZcnc3UDlDb1FFTWxnZDc5ZloKZlFJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg=="

When I am trying:

try PublicKey(base64Encoded: publicKey) // throws error

It throws error:

asn1ParsingFailed Couldn't parse the ASN1 key data. Please file a bug at https://goo.gl/y67MW6

But the next code is working:

guard
    let publicKeyData = Data(base64Encoded: publicKey),
    let publicKeyPem = String(data: publicKeyData, encoding: .utf8)
else {
    print("Can't decode base64")
    return
}

try PublicKey(pemEncoded: publicKeyPem) // is working
@MarkParker5 MarkParker5 changed the title Base64 Decoding Failed Base64 Decoding Failed (asn1ParsingFailed) Jul 21, 2023
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

1 participant