Skip to content

node:crypto createPublicKey rejects DER SPKI accepted by Node.js #29558

@kevgeoleo

Description

@kevgeoleo

What version of Bun is running?

1.3.13-canary.1+1b93e94b2

What platform is your computer?

Linux 5.10.0-12-amd64 x86_64 x86_64

What steps can reproduce the bug?

Hi,

I would like to report a behavior in Bun that can be reproduced using the below snippet:

import { createPublicKey } from 'node:crypto';

const key = createPublicKey({
  key: Buffer.from(
    'MDswDQYJKoZIhvcNAQEBBQADKgAwJwIg3wUvyMOfq7G6dT5bIM6keoShd9YGwP7PIc2Tfa8Q99ECAwEAAQ==',
    'base64'
  ),
  format: 'der',
  type: 'spki',
});

console.log(key);

What is the expected behavior?

root@KContainer:~/8004# node b.mjs
PublicKeyObject { Symbol(kKeyType): 'public' }

What do you see instead?

root@KContainer:~/8004# bun run b.mjs
1 | import { createPublicKey } from 'node:crypto';
2 |
3 | const key = createPublicKey({
                ^
error: Failed to read asymmetric key
      at /home/c01kele/8004/b.mjs:3:13
      at loadAndEvaluateModule (2:1)

Bun v1.3.13-canary.1+1b93e94b2 (Linux x64)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions