*/
public static RSAKey parse(final JSONObject jsonObject)
throws ParseException {
// Parse the mandatory public key parameters first
Base64URL n = new Base64URL(JSONObjectUtils.getString(jsonObject, "n"));
Base64URL e = new Base64URL(JSONObjectUtils.getString(jsonObject, "e"));
// Check key type
KeyType kty = KeyType.parse(JSONObjectUtils.getString(jsonObject, "kty"));
if (kty != KeyType.RSA) {
throw new ParseException("The key type \"kty\" must be RSA", 0);
}
// Parse the optional private key parameters
// 1st private representation
Base64URL d = null;
if (jsonObject.containsKey("d")) {
d = new Base64URL(JSONObjectUtils.getString(jsonObject, "d"));
}
// 2nd private (CRT) representation
Base64URL p = null;
if (jsonObject.containsKey("p")) {
p = new Base64URL(JSONObjectUtils.getString(jsonObject, "p"));
}
Base64URL q = null;
if (jsonObject.containsKey("q")) {
q = new Base64URL(JSONObjectUtils.getString(jsonObject, "q"));
}
Base64URL dp = null;
if (jsonObject.containsKey("dp")) {
dp = new Base64URL(JSONObjectUtils.getString(jsonObject, "dp"));
}
Base64URL dq= null;
if (jsonObject.containsKey("dq")) {
dq = new Base64URL(JSONObjectUtils.getString(jsonObject, "dq"));
}
Base64URL qi = null;
if (jsonObject.containsKey("qi")) {
qi = new Base64URL(JSONObjectUtils.getString(jsonObject, "qi"));
}
List<OtherPrimesInfo> oth = null;
if (jsonObject.containsKey("oth")) {
JSONArray arr = JSONObjectUtils.getJSONArray(jsonObject, "oth");
oth = new ArrayList<RSAKey.OtherPrimesInfo>(arr.size());
for (Object o : arr) {
if (o instanceof JSONObject) {
JSONObject otherJson = (JSONObject)o;
Base64URL r = new Base64URL(JSONObjectUtils.getString(otherJson, "r"));
Base64URL odq = new Base64URL(JSONObjectUtils.getString(otherJson, "dq"));
Base64URL t = new Base64URL(JSONObjectUtils.getString(otherJson, "t"));
OtherPrimesInfo prime = new OtherPrimesInfo(r, odq, t);
oth.add(prime);
}
}
}
// Get optional key use
KeyUse use = null;
if (jsonObject.containsKey("use")) {
use = KeyUse.parse(JSONObjectUtils.getString(jsonObject, "use"));
}
// Get optional key operations
Set<KeyOperation> ops = null;
if (jsonObject.containsKey("key_ops")) {
ops = KeyOperation.parse(JSONObjectUtils.getStringList(jsonObject, "key_ops"));
}
// Get optional intended algorithm
Algorithm alg = null;
if (jsonObject.containsKey("alg")) {
alg = new Algorithm(JSONObjectUtils.getString(jsonObject, "alg"));
}
// Get optional key ID
String kid = null;
if (jsonObject.containsKey("kid")) {
kid = JSONObjectUtils.getString(jsonObject, "kid");
}
// Get optional X.509 cert URL
URL x5u = null;
if (jsonObject.containsKey("x5u")) {
x5u = JSONObjectUtils.getURL(jsonObject, "x5u");
}
// Get optional X.509 cert thumbprint
Base64URL x5t = null;
if (jsonObject.containsKey("x5t")) {
x5t = new Base64URL(JSONObjectUtils.getString(jsonObject, "x5t"));
}
// Get optional X.509 cert chain
List<Base64> x5c = null;