3 releases (breaking)
0.3.0 | Jan 9, 2021 |
---|---|
0.2.0 | Jan 3, 2021 |
0.1.0 | Jul 25, 2020 |
#880 in Authentication
22 downloads per month
24KB
546 lines
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(())
}
lib.rs
:
jsonwebkey-convert
Handle Json Web Key without nightly rust compiler.
Load JSON Web Key Set
use jsonwebkey_convert::JsonWebKeySet;
let jwks: JsonWebKeySet = jwks_str.parse()?;
Convert PEM to JWK
pem_support
feature is required.
use jsonwebkey_convert::*;
use jsonwebkey_convert::der::FromPem;
let rsa_jwk = RSAPublicKey::from_pem(pem_data)?;
let jwk_byte_vec = serde_json::to_string(&rsa_jwk);
Convert JWK to PEM
pem_support
feature is required.
use jsonwebkey_convert::*;
use jsonwebkey_convert::der::ToPem;
let rsa_jwk: RSAPublicKey = jwk_data.parse()?;
let pem_data = rsa_jwk.to_pem()?;
Dependencies
~1.4–5.5MB
~116K SLoC