jsonwebkey-rs-repaired/jsonwebkey-convert-repaired
Matthieu Bessat cbb6688a45
Some checks failed
Build / tag (push) Has been cancelled
Build / build (map[cross:false os:macos-latest target:x86_64-apple-darwin test:true]) (push) Has been cancelled
Build / build (map[cross:false os:ubuntu-latest target:x86_64-unknown-linux-gnu test:true]) (push) Has been cancelled
Build / build (map[cross:false os:ubuntu-latest target:x86_64-unknown-linux-musl test:true]) (push) Has been cancelled
Build / build (map[cross:false os:windows-latest target:x86_64-pc-windows-msvc test:true]) (push) Has been cancelled
Build / release (push) Has been cancelled
Build / upload (x86_64-apple-darwin) (push) Has been cancelled
Build / upload (x86_64-pc-windows-msvc) (push) Has been cancelled
Build / upload (x86_64-unknown-linux-gnu) (push) Has been cancelled
Build / upload (x86_64-unknown-linux-musl) (push) Has been cancelled
build!(deps): upgrade bigint lib to solve issue downstream
2025-06-03 16:14:40 +02:00
..
src build!: rename to -repaired suffix 2025-06-03 16:14:04 +02:00
testfiles build!: rename to -repaired suffix 2025-06-03 16:14:04 +02:00
Cargo.toml build!(deps): upgrade bigint lib to solve issue downstream 2025-06-03 16:14:40 +02:00
README.md build!: rename to -repaired suffix 2025-06-03 16:14:04 +02:00

jsonwebkey-convert

Convert an RSA public key between Json Web Key and DER/PEM format.

Convert PEM to JWK

use jsonwebkey_convert::*;
use jsonwebkey_convert::der::FromPem;

fn main() -> Result<(), Error> {
    let pem_data = include_str!("../testfiles/test1.pem");
    let rsa_jwk = RSAPublicKey::from_pem(pem_data)?;
    let jwk_byte_vec = serde_json::to_string(&rsa_jwk);
    Ok(())
}

Convert JWK to PEM

use jsonwebkey_convert::*;
use jsonwebkey_convert::der::ToPem;

fn main() -> Result<(), Error> {
    let jwk_data = include_str!("../testfiles/test1.json");
    let rsa_jwk: RSAPublicKey = jwk_data.parse()?;
    let pem_data = rsa_jwk.to_pem()?;
    Ok(())
}