GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — generateKeyPairSync doesn't return KeyObject · Issue #25322 · nodejs/node

generateKeyPairSync doesn't return KeyObject #25322

New issue
Copy link
New issue
Copy link
Closed
Closed
generateKeyPairSync doesn't return KeyObject#25322
Copy link
Assignees
tniessen
Labels
confirmed-bugIssues and PRs for confirmed bugs.cryptoIssues and PRs related to the crypto subsystem.

Description

@panva
panva
opened on Jan 3, 2019
Issue body actions
  • Version: v11.6.0
  • Platform: macOS Mojave (10.14.2) Darwin C02TT3JQHTD6 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64

From crypto.generateKeyPair documentation

If a publicKeyEncoding or privateKeyEncoding was specified, this function behaves as if keyObject.export() had been called on its result. Otherwise, the respective part of the key is returned as a KeyObject.

This documentation part is missing from crypto.generateKeyPairSync but you can still omit the encoding objects, then a simple empty object {} is returned instead of an expected KeyObject.

/cc @tniessen

Examples:

const { generateKeyPairSync } = require('crypto')

console.log('generateKeyPairSync result', generateKeyPairSync('rsa', { modulusLength: 2048 }))
// => generateKeyPairSync result { publicKey: {}, privateKey: {} }

Activity

  1. panva
    changed the title [-]generateKeyPair (+sync) doesn't return KeyObject as documented[/-] [+]generateKeyPair (+sync) doesn't return KeyObject as documented when promisified[/+] on Jan 3, 2019
  2. panva
    changed the title [-]generateKeyPair (+sync) doesn't return KeyObject as documented when promisified[/-] [+]generateKeyPairSync doesn't return KeyObject[/+] on Jan 3, 2019
  3. tniessen
    self-assigned this
    on Jan 3, 2019
  4. tniessen
    added
    confirmed-bugIssues and PRs for confirmed bugs.
    cryptoIssues and PRs related to the crypto subsystem.
    on Jan 3, 2019
  5. tniessen commented on Jan 3, 2019

    @tniessen
    tniessen
    on Jan 3, 2019
    Member
    More actions

    Thanks for reporting this! The problem is that the native (C++) key object is being returned, not the JavaScript key object, that's why the object appears to be empty.

    > const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', { modulusLength: 2048 })
    undefined
    > publicKey.getAsymmetricKeyType()
    'rsa'
    > publicKey.getSymmetricKeySize()
    C:\WINDOWS\system32\cmd.exe - node[6416]: src\node_crypto.cc:3350: Assertion `(key_type_) == (kKeyTypeSecret)' failed.
     1: 00007FF7F0EC3FDA v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4714
     2: 00007FF7F0E68AD6 uv_loop_fork+80918
     3: 00007FF7F0E68B8F uv_loop_fork+81103
     4: 00007FF7F0D8682F std::vector<v8::CpuProfileDeoptFrame,std::allocator<v8::CpuProfileDeoptFrame> >::vector<v8::CpuProfileDeoptFrame,std::allocator<v8::CpuProfileDeoptFrame> >+102815
     5: 00007FF7F12D20BE v8::internal::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>+59870
     6: 00007FF7F12D3620 v8::internal::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>+65344
     7: 00007FF7F12D25B9 v8::internal::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>+61145
     8: 00007FF7F12D249B v8::internal::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>::ZoneVector<v8::internal::compiler::MoveOperands * __ptr64>+60859
     9: 00000038CF650361
  6. tniessen
    added a commit that references this issue on Jan 3, 2019

    crypto: fix key object wrapping in sync keygen

    cdd91ee
  7. danbev
    closed this as completedin 7afdfaeon Jan 7, 2019
  8. addaleax
    added a commit that references this issue on Jan 9, 2019

    crypto: fix key object wrapping in sync keygen

    32e45b2
  9. refack
    added a commit that references this issue on Jan 14, 2019

    crypto: fix key object wrapping in sync keygen

    c8c9290
  10. BridgeAR
    added a commit that references this issue on Jan 16, 2019

    crypto: fix key object wrapping in sync keygen

    79b089f
  11. tniessen commented on Dec 19, 2019

    @tniessen
    tniessen
    on Dec 19, 2019
    Member
    More actions

    @cqupt-yifanwu Your code creates a key pair and returns them as a pair of Buffers, because you specified the publicKeyEncoding and privateKeyEncoding options. Buffer does not have properties such as getAsymmetricKeyType and getSymmetricKeySize. You can either remove the encoding options and use KeyObjects, or create KeyObjects from the returned Buffers.

  12. cqupt-yifanwu commented on Dec 19, 2019

    @cqupt-yifanwu
    cqupt-yifanwu
    on Dec 19, 2019
    More actions

    @cqupt-yifanwu Your code creates a key pair and returns them as a pair of Buffers, because you specified the publicKeyEncoding and privateKeyEncoding options. Buffer does not have properties such as getAsymmetricKeyType and getSymmetricKeySize. You can either remove the encoding options and use KeyObjects, or create KeyObjects from the returned Buffers.

    i want to Communication with java Server in ECDH encryption way ,but the generateKeyPairSync retruns privateKey has different length with java server

  13. tniessen commented on Dec 19, 2019

    @tniessen
    tniessen
    on Dec 19, 2019
    Member
    More actions

    @cqupt-yifanwu Please open a new issue for that (preferably in nodejs/help), and please include code to reproduce your problem!

  14. sjarmak
    added a commit that references this issue on Jul 27, 2026

    crypto: fix key object wrapping in sync keygen

    7afdfae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tniessen
    tniessen

Labels

confirmed-bugIssues and PRs for confirmed bugs.cryptoIssues and PRs related to the crypto subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.