jwcrypto에서 동일한 키를 가진 node-jose와 동일한 JWE를 생성하기 위해 고심하고 있습니다. 목표는 노드 - jose에 키를 생성하고 pubkey를 jwcrypto로 내 보내 페이로드를 암호화 한 다음 노드 - 조스에 의해 소비되고 암호 해독됩니다.EC 키를 사용하여 node-jose (js)와 jwcrypto (python) 사이의 상호 운용성?
노드 호세에서 완전히 내 테스트가 잘 작동:
var jose = require("node-jose")
var keyStore = jose.JWK.createKeyStore()
keyStore.generate('EC', 'P-521').then(function (result) {
// Use exported key to encrypt something (so we see the same thing jwcrypto does)
jose.JWK.asKey(result.toJSON()).then(function(result) {
jose.JWE.createEncrypt(result).update('this is a test payload').final().then(function (result) {
jose.JWE.createDecrypt(keyStore).decrypt(result).then(function (result) {
// Result is good
console.log(result)
})
})
})
을하지만, 내가 파이썬에서 동일한 작업을 수행 할 때, 노드 호세가 다른 JWE를 생성합니다
key = jwk.JWK(**json.loads(the_exported_key))
# This key looks exactly the same as the exported key in node-jose
print(key.export(private_key=False))
payload = "this is a test payload"
header = {
'alg': 'ECDH-ES',
'enc': 'A128CBC-HS256',
}
my_jwe = jwe.JWE(payload.encode('utf-8'), header)
my_jwe.add_recipient(key)
노드 - 호세 my_jwe의 암호 해독을 시도하면 "오류 : 키를 찾을 수 없습니다"와 함께 실패합니다. 이상하게도 (JWE를 처음 사용하는 ...), 두 가지 암호화 결과가 있습니다 (아래 예 참조). jwcrypto를 node-jose처럼 '헤더'값을 필요로하지 않는 방법을 놓치고 있다고 생각합니다.
노드 호세 예 (정크 데이터) :
{
ciphertext: "1e7YX6hNDJWJELhHTNXEOg",
iv: "oQZZq2smHX8u8MMwoC6NBA",
protected: "eyJhbGciOi".....(very long string),
tag: "3NfEqx9f2ivL8QodG5Duaw",
}
jwcrypto (정크 데이터) :
{
ciphertext: "7ldKnkcsLZUy-SXFRv_HpkWOsb-YUUlNFv-4M5yZhCA",
iv: "1uErMiK_RWcaPXPCPq12Uw",
header: {
alg: "ECDH-ES",
enc: "A128CBC-HS256",
epk: {
crv: "P-521",
kty: "EC",
x: different from the exported key, I assume this is expected 'epk',
y: different from the exported key, I assume this is expected 'epk',
},
kid: "JCU3sWKfirVybFbpy2NPOnq-4-43JiemRZLO5dmPMVo"
},
tag: "51AMFyCJld5uPyMFLLl-sw",
}