MCPcopy Create free account
hub / github.com/ampproject/amphtml / importPkcsKey

Method importPkcsKey

src/service/crypto-impl.js:171–180  ·  view source on GitHub ↗

* Converts an RSA JSON Web Key object to a browser-native cryptographic key. * As a precondition, `isPkcsAvailable()` must be `true`. * * @param {!Object} jwk a deserialized RSA JSON Web Key, as specified in * Section 6.3 of RFC 7518 * @return {!Promise<!webCrypto.CryptoKey>} *

(jwk)

Source from the content-addressed store, hash-verified

169 * @throws {TypeError} if `jwk` is not an RSA JSON Web Key
170 */
171 importPkcsKey(jwk) {
172 devAssert(this.isPkcsAvailable());
173 // Safari 10 and earlier want this as an ArrayBufferView.
174 const keyData = this.isLegacyWebkit_
175 ? utf8Encode(JSON.stringify(/** @type {!JsonObject} */ (jwk)))
176 : /** @type {!webCrypto.JsonWebKey} */ (jwk);
177 return /** @type {!Promise<!webCrypto.CryptoKey>} */ (
178 this.subtle.importKey('jwk', keyData, this.pkcsAlgo, true, ['verify'])
179 );
180 }
181
182 /**
183 * Verifies an RSASSA-PKCS1-v1_5 signature with a SHA-256 hash. As a

Callers 2

scanForTokens_Method · 0.80
fetchAndAddKeys_Method · 0.80

Calls 4

isPkcsAvailableMethod · 0.95
devAssertFunction · 0.90
utf8EncodeFunction · 0.90
stringifyMethod · 0.80

Tested by

no test coverage detected