I see https://w3c-ccg.github.io/lds-jws2020/ .
This suite support cryptographic agility, see [RFC7696]. This table maps a key type to a subset of [IANA_JOSE] supported signing and encryption algorithms.
kty crvOrSize signature keyAgreement encryption
OKP Ed25519 EdDSA ECDH-ES+A256KW
OKP X25519 ECDH ECDH-ES+A256KW
EC secp256k1 ES256K ECDH ECDH-ES+A256KW
EC P-256 ES256 ECDH ECDH-ES+A256KW
EC P-384 ES384 ECDH ECDH-ES+A256KW
RSA 2048 PS256 RSA-OAEP
I would like the stuff in bold because I would like JWE with P-256?
Here is some babbling from earlier:
[edit most of this thread is blabbering]
This is kind of strange looking:
const kek = concatKDF(sharedSecret, keyLen, alg)
const res = xc20pEncrypter(kek)(cek)
function xc20pEncrypter(key: Uint8Array): (cleartext: Uint8Array, aad?: Uint8Array) => EncryptionResult {
const cipher = new XChaCha20Poly1305(key)
return (cleartext: Uint8Array, aad?: Uint8Array) => {
const iv = randomBytes(cipher.nonceLength)
const sealed = cipher.seal(iv, cleartext, aad)
return {
ciphertext: sealed.subarray(0, sealed.length - cipher.tagLength),
tag: sealed.subarray(sealed.length - cipher.tagLength),
iv,
}
}
}
source: https://github.com/decentralized-identity/did-jwt/blob/master/src/xc20pEncryption.ts#L126-L204
[bshambaugh]
Maybe I should ask with an issue what is needed.I'm trying to reverse engineer the code.https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6I need instead:
| ECDH-ES+A256KW | ECDH-ES using Concat KDF and CEK wrapped with |
| | "A256KW"
[bshambaugh]
I can get A256KW here: https://github.com/StableLib/stablelib/blob/master/packages/aes-kw/aes-kw.test.ts
aes-kw.test.ts
// Copyright (C) 2020 Tobias Looker
// MIT License. See LICENSE file for details.
import { AESKW } from "./aes-kw";
import { encode, decode } from "@stablelib/hex";
https://github.com/[StableLib/stablelib](https://github.com/StableLib/stablelib)|StableLib/stablelibStableLib/stablelib
[bshambaugh]
I have been eying: https://github.com/panva/jose/tree/main/src/jwe
[bshambaugh]
And maybe the jose npm library is the way to go. I still need to fiddle with my JWK, PEM, or DER representation.
[bshambaugh]
the results of that: https://gist.github.com/bshambaugh/4014f8a11025b42774b75f2bbd3f9be7 (edited)
[bshambaugh]
going through the xc20pEncrypter code is manual mode.
[bshambaugh]
I'm trying to match this interface with my function: https://github.com/decentralized-identity/did-jwt/blob/master/src/JWE.ts#L55-L60 (edited)
JWE.ts
export interface Encrypter {
alg: string
enc: string
encrypt: (cleartext: Uint8Array, protectedHeader: ProtectedHeader, aad?: Uint8Array) => Promise
encryptCek?: (cek: Uint8Array) => Promise
https://github.com/[decentralized-identity/did-jwt](https://github.com/decentralized-identity/did-jwt)|decentralized-identity/did-jwtdecentralized-identity/did-jwt
[bshambaugh]
It's not really clear how the JOSE library is going to give me that easily. I think if I can match the interface it will work with the rest of the library.
[bshambaugh]
well hmm....here's an idea of how the JOSE library looks:https://github.com/panva/jose/blob/main/docs/functions/jwe_flattened_decrypt.flattenedDecrypt.md#readme
[bshambaugh]
const jwe = {
ciphertext: '9EzjFISUyoG-ifC2mSihfP0DPC80yeyrxhTzKt1C_VJBkxeBG0MI4Te61Pk45RAGubUvBpU9jm4',
iv: '8Fy7A_IuoX5VXG9s',
tag: 'W76IYV6arGRuDSaSyWrQNg',
encrypted_key: 'Z6eD4UK_yFb5ZoKvKkGAdqywEG_m0e4IYo0x8Vf30LAMJcsc-_zSgIeiF82teZyYi2YYduHKoqImk7MRnoPZOlEs0Q5BNK1OgBmSOhCE8DFyqh9Zh48TCTP6lmBQ52naqoUJFMtHzu-0LwZH26hxos0GP3Dt19O379MJB837TdKKa87skq0zHaVLAquRHOBF77GI54Bc7O49d8aOrSu1VEFGMThlW2caspPRiTSePDMDPq7_WGk50izRhB3Asl9wmP9wEeaTrkJKRnQj5ips1SAZ1hDBsqEQKKukxP1HtdcopHV5_qgwU8Hjm5EwSLMluMQuiE6hwlkXGOujZLVizA',
aad: 'VGhlIEZlbGxvd3NoaXAgb2YgdGhlIFJpbmc',
protected: 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0'
}
const {
plaintext,
protectedHeader,
additionalAuthenticatedData
} = await jose.flattenedDecrypt(jwe, privateKey)
console.log(protectedHeader)
const decoder = new TextDecoder()
console.log(decoder.decode(plaintext))
console.log(decoder.decode(additionalAuthenticatedData))
[bshambaugh]
compare to: https://github.com/decentralized-identity/did-jwt/blob/master/src/JWE.ts#L37-L44
[bshambaugh]
export interface JWE {
protected: string
iv: string
ciphertext: string
tag: string
aad?: string
recipients?: Recipient[]
}
[bshambaugh]
they should ultimately both follow a standard.
[bshambaugh]
"https://www.rfc-editor.org/rfc/rfc7516 , https://www.rfc-editor.org/rfc/rfc7518
I see https://w3c-ccg.github.io/lds-jws2020/ .
This suite support cryptographic agility, see [RFC7696]. This table maps a key type to a subset of [IANA_JOSE] supported signing and encryption algorithms.
kty crvOrSize signature keyAgreement encryption
OKP Ed25519 EdDSA ECDH-ES+A256KW
OKP X25519 ECDH ECDH-ES+A256KW
EC secp256k1 ES256K ECDH ECDH-ES+A256KW
EC P-256 ES256 ECDH ECDH-ES+A256KW
EC P-384 ES384 ECDH ECDH-ES+A256KW
RSA 2048 PS256 RSA-OAEP
I would like the stuff in bold because I would like JWE with P-256?
Here is some babbling from earlier:
[edit most of this thread is blabbering]
This is kind of strange looking:
const kek = concatKDF(sharedSecret, keyLen, alg)
const res = xc20pEncrypter(kek)(cek)
function xc20pEncrypter(key: Uint8Array): (cleartext: Uint8Array, aad?: Uint8Array) => EncryptionResult {
const cipher = new XChaCha20Poly1305(key)
return (cleartext: Uint8Array, aad?: Uint8Array) => {
const iv = randomBytes(cipher.nonceLength)
const sealed = cipher.seal(iv, cleartext, aad)
return {
ciphertext: sealed.subarray(0, sealed.length - cipher.tagLength),
tag: sealed.subarray(sealed.length - cipher.tagLength),
iv,
}
}
}
source: https://github.com/decentralized-identity/did-jwt/blob/master/src/xc20pEncryption.ts#L126-L204
[bshambaugh]
Maybe I should ask with an issue what is needed.I'm trying to reverse engineer the code.https://www.rfc-editor.org/rfc/rfc7518.html#section-4.6I need instead:
| ECDH-ES+A256KW | ECDH-ES using Concat KDF and CEK wrapped with |
| | "A256KW"
[bshambaugh]
I can get A256KW here: https://github.com/StableLib/stablelib/blob/master/packages/aes-kw/aes-kw.test.ts
aes-kw.test.ts
// Copyright (C) 2020 Tobias Looker
// MIT License. See LICENSE file for details.
import { AESKW } from "./aes-kw";
import { encode, decode } from "@stablelib/hex";
https://github.com/[StableLib/stablelib](https://github.com/StableLib/stablelib)|StableLib/stablelibStableLib/stablelib
[bshambaugh]
I have been eying: https://github.com/panva/jose/tree/main/src/jwe
[bshambaugh]
And maybe the jose npm library is the way to go. I still need to fiddle with my JWK, PEM, or DER representation.
[bshambaugh]
the results of that: https://gist.github.com/bshambaugh/4014f8a11025b42774b75f2bbd3f9be7 (edited)
[bshambaugh]
going through the xc20pEncrypter code is manual mode.
[bshambaugh]
I'm trying to match this interface with my function: https://github.com/decentralized-identity/did-jwt/blob/master/src/JWE.ts#L55-L60 (edited)
JWE.ts
export interface Encrypter {
alg: string
enc: string
encrypt: (cleartext: Uint8Array, protectedHeader: ProtectedHeader, aad?: Uint8Array) => Promise
encryptCek?: (cek: Uint8Array) => Promise
https://github.com/[decentralized-identity/did-jwt](https://github.com/decentralized-identity/did-jwt)|decentralized-identity/did-jwtdecentralized-identity/did-jwt
[bshambaugh]
It's not really clear how the JOSE library is going to give me that easily. I think if I can match the interface it will work with the rest of the library.
[bshambaugh]
well hmm....here's an idea of how the JOSE library looks:https://github.com/panva/jose/blob/main/docs/functions/jwe_flattened_decrypt.flattenedDecrypt.md#readme
[bshambaugh]
const jwe = {
ciphertext: '9EzjFISUyoG-ifC2mSihfP0DPC80yeyrxhTzKt1C_VJBkxeBG0MI4Te61Pk45RAGubUvBpU9jm4',
iv: '8Fy7A_IuoX5VXG9s',
tag: 'W76IYV6arGRuDSaSyWrQNg',
encrypted_key: 'Z6eD4UK_yFb5ZoKvKkGAdqywEG_m0e4IYo0x8Vf30LAMJcsc-_zSgIeiF82teZyYi2YYduHKoqImk7MRnoPZOlEs0Q5BNK1OgBmSOhCE8DFyqh9Zh48TCTP6lmBQ52naqoUJFMtHzu-0LwZH26hxos0GP3Dt19O379MJB837TdKKa87skq0zHaVLAquRHOBF77GI54Bc7O49d8aOrSu1VEFGMThlW2caspPRiTSePDMDPq7_WGk50izRhB3Asl9wmP9wEeaTrkJKRnQj5ips1SAZ1hDBsqEQKKukxP1HtdcopHV5_qgwU8Hjm5EwSLMluMQuiE6hwlkXGOujZLVizA',
aad: 'VGhlIEZlbGxvd3NoaXAgb2YgdGhlIFJpbmc',
protected: 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0'
}
const {
plaintext,
protectedHeader,
additionalAuthenticatedData
} = await jose.flattenedDecrypt(jwe, privateKey)
console.log(protectedHeader)
const decoder = new TextDecoder()
console.log(decoder.decode(plaintext))
console.log(decoder.decode(additionalAuthenticatedData))
[bshambaugh]
compare to: https://github.com/decentralized-identity/did-jwt/blob/master/src/JWE.ts#L37-L44
[bshambaugh]
export interface JWE {
protected: string
iv: string
ciphertext: string
tag: string
aad?: string
recipients?: Recipient[]
}
[bshambaugh]
they should ultimately both follow a standard.
[bshambaugh]
"https://www.rfc-editor.org/rfc/rfc7516 , https://www.rfc-editor.org/rfc/rfc7518