Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An equivalent function to node-jose's createEncrypt #28

Open
x86y opened this issue Nov 13, 2023 · 0 comments
Open

An equivalent function to node-jose's createEncrypt #28

x86y opened this issue Nov 13, 2023 · 0 comments

Comments

@x86y
Copy link

x86y commented Nov 13, 2023

Hi. First of all, thanks for josekit.

I'm trying to port my javascript code to rust using josekit-rs. Specifically the following code:

let JWK_KEY = {
    "kty":  ("RSA"),
    "e":  ("AQAB"),
    "kid":  ("5fe64480-444f-4d4a-af27-aa2a750239af"),
    "n":  ("3NxCce6lBGfYCDCMejT1mc9Y0YmGx-S6herOLq6DQw1hyULsKsdOLWM47hAfxL4tTx1Y-lE082xyuKg96a9zXhoGiEvwXYFJAMxtQUcbxvTLYy2rtgclVok5UkOIE1IoYPnZ8EqTDk7YcWwxfRPGw-o1Kpuq7cB5Eymvoiq7x566PSPDFkZZGBdvlhNNK1qgUyEtpAxI9_6zfiKHVjmJjzAGh9UoiKiWAEIFUwB-SayhekZmDvM1h2OwOeinIA19R4dwloP1HtdRyuTLKxfppixgMDiWi6EO_xsY5FJwsO0Ak7ydLu3avI8_ZtwZOCYDzH7xz9ISecWkctiPHDHMBw"),
}
JWE.createEncrypt({format: "compact"}, JWK_KEY).update(payload).final()

I've used the following rust

    let mut payload = JwtPayload::new();
    let JWK_KEY: Map<String, serde_json::Value> = (THE_ABOVE_JSON).as_object().unwrap().clone();
    payload.set_subject(...);
    let mut header = JweHeader::new();
    header.set_content_encryption("A128CBC-HS256");
    let key = Jwk::from_map(JWK_KEY)?;
    let enc = josekit::jwe::RSA_OAEP.encrypter_from_jwk(&key)?;
    let jwt = jwt::encode_with_encrypter(&payload, &header, &enc)?;

The final encoded jwt s are not equal, but the JWK_KEY and payload are indeed equal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant