GithubHelp home page GithubHelp logo

Comments (6)

chris-wood avatar chris-wood commented on August 25, 2024 1

My understanding of the raw representation of CryptoKey objects is that they are not equivalent to the HPKE public key serialized representation. If that's the case, then yes, something like the exportKey function you propose for KEMs would work well!

from hpke-js.

dajiaji avatar dajiaji commented on August 25, 2024 1

My understand of the raw representation of CryptoKey objects is that they are not equivalent to the HPKE public key serialized representation.

I guess in some cases they will be the same, in other cases they will be different. Understood. At least, we might have to avoid the function name like exportKey which misleads that it's the same as Web Crypto API. Anyway, I'll implement it.

I'll ask you to review the PR. Wait for a few days.

from hpke-js.

chris-wood avatar chris-wood commented on August 25, 2024 1

Encoding the public key is sufficient for now -- thank you! This works perfectly.

from hpke-js.

dajiaji avatar dajiaji commented on August 25, 2024

Hi @chris-wood,

Actually, only in case for DHKEM(P-*), you can convert between raw keys and CryptoKeys in the following way.

const suite = new CipherSuite({
    kem: Kem.DhkemP256HkdfSha256,
    kdf: Kdf.HkdfSha256,
    aead: Aead.Aes128Gcm
});

const rkp = await suite.generateKeyPair();

// CryptoKey to raw
const raw = await crypto.subtle.exportKey("raw", rkp.publicKey);

// raw to CryptoKey
const kemCtx = await suite.kemContext();
const cryptoKey = await kemCtx.importKey("raw", raw, true);

This method is not available in DHKEM(X*), so it might be better to have a utility function, for example, KemInterface.exportKey("raw", xxx).

KemInterface.exportKey() so that the upper application layer does not have to worry about Web Crypto API compatibility.

Is this what you want?

from hpke-js.

chris-wood avatar chris-wood commented on August 25, 2024

Perfect -- thanks!

from hpke-js.

dajiaji avatar dajiaji commented on August 25, 2024

... I'm very sorry. I was going to implement it, but I had already done it 2 months ago.
I completely forgot about it...

Could you update hpke-js to v0.18.2 and try it?

const suite = new CipherSuite({
    kem: Kem.DhkemP256HkdfSha256,
    kdf: Kdf.HkdfSha256,
    aead: Aead.Aes128Gcm
});
const kemContext = await suite.kemContext();
const kp = await kemContext.generateKeyPair();
// CryptoKey to raw
const rawPubKey = await kemContext.serializePublicKey(kp.publicKey);
// raw to CryptoKey
const pubKey = await kemContext.deserializePublicKey(rawPubKey);

If you want serializePrivateKey()/deserializePrivateKey() as well, feel free to ask me.

from hpke-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.