JsonWebKey CryptoKeyAES::exportJwk() const { JsonWebKey result; result.kty = "oct"; result.k = base64URLEncode(m_key); result.key_ops = usages(); result.ext = extractable(); return result; }
void JSCryptoKeySerializationJWK::buildJSONForRSAComponents(JSC::ExecState* exec, const CryptoKeyDataRSAComponents& data, JSC::JSObject* result) { addToJSON(exec, result, "kty", "RSA"); addToJSON(exec, result, "n", base64URLEncode(data.modulus())); addToJSON(exec, result, "e", base64URLEncode(data.exponent())); if (data.type() == CryptoKeyDataRSAComponents::Type::Public) return; addToJSON(exec, result, "d", base64URLEncode(data.privateExponent())); if (!data.hasAdditionalPrivateKeyParameters()) return; addToJSON(exec, result, "p", base64URLEncode(data.firstPrimeInfo().primeFactor)); addToJSON(exec, result, "q", base64URLEncode(data.secondPrimeInfo().primeFactor)); addToJSON(exec, result, "dp", base64URLEncode(data.firstPrimeInfo().factorCRTExponent)); addToJSON(exec, result, "dq", base64URLEncode(data.secondPrimeInfo().factorCRTExponent)); addToJSON(exec, result, "qi", base64URLEncode(data.secondPrimeInfo().factorCRTCoefficient)); if (data.otherPrimeInfos().isEmpty()) return; JSArray* oth = constructEmptyArray(exec, 0, exec->lexicalGlobalObject(), data.otherPrimeInfos().size()); for (size_t i = 0, size = data.otherPrimeInfos().size(); i < size; ++i) { JSObject* jsPrimeInfo = constructEmptyObject(exec); addToJSON(exec, jsPrimeInfo, "r", base64URLEncode(data.otherPrimeInfos()[i].primeFactor)); addToJSON(exec, jsPrimeInfo, "d", base64URLEncode(data.otherPrimeInfos()[i].factorCRTExponent)); addToJSON(exec, jsPrimeInfo, "t", base64URLEncode(data.otherPrimeInfos()[i].factorCRTCoefficient)); oth->putDirectIndex(exec, i, jsPrimeInfo); } result->putDirect(exec->vm(), Identifier(exec, "oth"), oth); }
void JSCryptoKeySerializationJWK::buildJSONForOctetSequence(ExecState* exec, const Vector<uint8_t>& keyData, JSObject* result) { addToJSON(exec, result, "kty", "oct"); addToJSON(exec, result, "k", base64URLEncode(keyData)); }
static void buildJSONForOctetSequence(ExecState* exec, const Vector<uint8_t>& keyData, JSObject* result) { addToJSON(exec, result, "kty", "oct"); addToJSON(exec, result, "k", base64URLEncode(keyData)); }
JsonWebKey CryptoKeyRSA::exportJwk() const { JsonWebKey result; result.kty = "RSA"; result.key_ops = usages(); result.ext = extractable(); auto keyData = exportData(); const auto& rsaKeyData = downcast<CryptoKeyDataRSAComponents>(*keyData); // public key result.n = base64URLEncode(rsaKeyData.modulus()); result.e = base64URLEncode(rsaKeyData.exponent()); if (rsaKeyData.type() == CryptoKeyDataRSAComponents::Type::Public) return result; // private key result.d = base64URLEncode(rsaKeyData.privateExponent()); if (!rsaKeyData.hasAdditionalPrivateKeyParameters()) return result; result.p = base64URLEncode(rsaKeyData.firstPrimeInfo().primeFactor); result.q = base64URLEncode(rsaKeyData.secondPrimeInfo().primeFactor); result.dp = base64URLEncode(rsaKeyData.firstPrimeInfo().factorCRTExponent); result.dq = base64URLEncode(rsaKeyData.secondPrimeInfo().factorCRTExponent); result.qi = base64URLEncode(rsaKeyData.secondPrimeInfo().factorCRTCoefficient); if (rsaKeyData.otherPrimeInfos().isEmpty()) return result; Vector<RsaOtherPrimesInfo> oth; for (auto info : rsaKeyData.otherPrimeInfos()) { RsaOtherPrimesInfo otherInfo; otherInfo.r = base64URLEncode(info.primeFactor); otherInfo.d = base64URLEncode(info.factorCRTExponent); otherInfo.t = base64URLEncode(info.factorCRTCoefficient); oth.append(WTFMove(otherInfo)); } result.oth = WTFMove(oth); return result; }