std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const { ASSERT(extractable()); notImplemented(); return nullptr; }
JsonWebKey CryptoKeyAES::exportJwk() const { JsonWebKey result; result.kty = "oct"; result.k = base64URLEncode(m_key); result.key_ops = usages(); result.ext = extractable(); return result; }
std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const { ASSERT(extractable()); switch (CCRSAGetKeyType(m_platformKey)) { case ccRSAKeyPublic: { Vector<uint8_t> modulus; Vector<uint8_t> publicExponent; CCCryptorStatus status = getPublicKeyComponents(m_platformKey, modulus, publicExponent); if (status) { WTFLogAlways("Couldn't get RSA key components, status %d", status); return nullptr; } return CryptoKeyDataRSAComponents::createPublic(modulus, publicExponent); } case ccRSAKeyPrivate: // Not supported yet. default: return nullptr; } }
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; }
std::unique_ptr<CryptoKeyData> CryptoKeyAES::exportData() const { ASSERT(extractable()); return CryptoKeyDataOctetSequence::create(m_key); }