diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/fr/web/api/subtlecrypto/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/fr/web/api/subtlecrypto/index.html')
-rw-r--r-- | files/fr/web/api/subtlecrypto/index.html | 298 |
1 files changed, 298 insertions, 0 deletions
diff --git a/files/fr/web/api/subtlecrypto/index.html b/files/fr/web/api/subtlecrypto/index.html new file mode 100644 index 0000000000..6788ee5bdb --- /dev/null +++ b/files/fr/web/api/subtlecrypto/index.html @@ -0,0 +1,298 @@ +--- +title: SubtleCrypto +slug: Web/API/SubtleCrypto +tags: + - API + - Advanced + - Cryptography + - Encryption + - Interface + - NeedsTranslation + - Reference + - SubtleCrypto + - TopicStub + - Web Crypto API +translation_of: Web/API/SubtleCrypto +--- +<div>{{APIRef("Web Crypto API")}}{{SecureContext_header}}</div> + +<p><span class="seoSummary">The <code><strong>SubtleCrypto</strong></code> interface of the <a href="/en-US/docs/Web/API/Web_Crypto_API">Web Crypto API</a> provides a number of low-level cryptographic functions. Access to the features of <code>SubtleCrypto</code> is obtained through the {{domxref("Crypto.subtle", "subtle")}} property of the {{domxref("Crypto")}} object you get from {{domxref("Window.crypto")}}.</span></p> + +<div class="warning"> +<p><strong>Warning:</strong> This API provides a number of low-level cryptographic primitives. It's very easy to misuse them, and the pitfalls involved can be very subtle.</p> + +<p>Even assuming you use the basic cryptographic functions correctly, secure key management and overall security system design are extremely hard to get right, and are generally the domain of specialist security experts.</p> + +<p>Errors in security system design and implementation can make the security of the system completely ineffective.</p> + +<p><strong>If you're not sure you know what you are doing, you probably shouldn't be using this API.</strong></p> +</div> + +<h2 id="Properties">Properties</h2> + +<p><em>This interface doesn't inherit any properties, as it has no parent interface.</em></p> + +<h2 id="Methods">Methods</h2> + +<p><em>This interface doesn't inherit any methods, as it has no parent interface.</em></p> + +<dl> + <dt>{{domxref("SubtleCrypto.encrypt()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fufills with the encrypted data corresponding to the clear text, algorithm, and key given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.decrypt()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with the clear data corresponding to the encrypted text, algorithm, and key given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.sign()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with the signature corresponding to the text, algorithm, and key given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.verify()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a {{jsxref("Boolean")}} value indicating if the signature given as a parameter matches the text, algorithm, and key that are also given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.digest()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a digest generated from the algorithm and text given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.generateKey()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a newly-generated {{domxref("CryptoKey")}}, for symmetrical algorithms, or a {{domxref("CryptoKeyPair")}}, containing two newly generated keys, for asymmetrical algorithms. These will match the algorithm, usages, and extractability given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.deriveKey()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a newly generated {{domxref("CryptoKey")}} derived from the master key and specific algorithm given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.deriveBits()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a newly generated buffer of pseudo-random bits derived from the master key and specific algorithm given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.importKey()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a {{domxref("CryptoKey")}} corresponding to the format, the algorithm, raw key data, usages, and extractability given as parameters.</dd> + <dt>{{domxref("SubtleCrypto.exportKey()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a buffer containing the key in the requested format.</dd> + <dt>{{domxref("SubtleCrypto.wrapKey()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a wrapped symmetric key for usage (transfer and storage) in insecure environments. The wrapped key matches the format specified in the given parameters, and wrapping is done by the given wrapping key, using the specified algorithm.</dd> + <dt>{{domxref("SubtleCrypto.unwrapKey()")}}</dt> + <dd>Returns a {{jsxref("Promise")}} that fulfills with a {{domxref("CryptoKey")}} corresponding to the wrapped key given in the parameter.</dd> +</dl> + +<h2 id="Using_SubtleCrypto">Using SubtleCrypto</h2> + +<p>We can split the functions implemented by this API into two groups: cryptography functions and key management functions.</p> + +<h3 id="Cryptography_functions">Cryptography functions</h3> + +<p>These are the functions you can use to implement security features such as privacy and authentication in a system. The <code>SubtleCrypto</code> API provides the following cryptography functions:</p> + +<p>* {{DOMxRef("SubtleCrypto.sign","sign()")}} and {{DOMxRef("SubtleCrypto.verify","verify()")}}: create and verify digital signatures.<br> + * {{DOMxRef("SubtleCrypto.encrypt","encrypt()")}} and {{DOMxRef("SubtleCrypto.decrypt","decrypt()")}}: encrypt and decrypt data.<br> + * {{DOMxRef("SubtleCrypto.digest","digest()")}}: create a fixed-length, collision-resistant digest of some data.</p> + +<h3 id="Key_management_functions">Key management functions</h3> + +<p>Except for {{DOMxRef("SubtleCrypto.digest","digest()")}}, all the cryptography functions in the API use cryptographic keys. In the <code>SubtleCrypto</code> API a cryptographic key is represented using a {{DOMxRef("CryptoKey","CryptoKey")}} object. To perform operations like signing and encrypting, you pass a {{DOMxRef("CryptoKey","CryptoKey")}} object into the {{DOMxRef("SubtleCrypto.sign","sign()")}} or {{DOMxRef("SubtleCrypto.encrypt","encrypt()")}} function.</p> + +<h4 id="Generating_and_deriving_keys">Generating and deriving keys</h4> + +<p>The {{DOMxRef("SubtleCrypto.generateKey","generateKey()")}} and {{DOMxRef("SubtleCrypto.deriveKey","deriveKey()")}} functions both create a new {{DOMxRef("CryptoKey")}} object.</p> + +<p>The difference is that <code>generateKey()</code> will generate a new distinct key value each time you call it, while <code>deriveKey()</code> derives a key from some initial keying material. If you provide the same keying material to two separate calls to <code>deriveKey()</code>, you will get two <code>CryptoKey</code> objects that have the same underlying value. This is useful if, for example, you want to derive an encryption key from a password and later derive the same key from the same password to decrypt the data.</p> + +<h4 id="Importing_and_exporting_keys">Importing and exporting keys</h4> + +<p>To make keys available outside your app, you need to export the key, and that's what {{DOMxRef("SubtleCrypto.exportKey","exportKey()")}} is for. You can choose one of a number of export formats.</p> + +<p>The inverse of <code>exportKey()</code> is {{DOMxRef("SubtleCrypto.importKey","importKey()")}}. You can import keys from other systems, and support for standard formats like <a href="https://tools.ietf.org/html/rfc5208">PKCS #8</a> and <a href="https://tools.ietf.org/html/rfc7517">JSON Web Key</a> helps you do this. The <code>exportKey()</code> function exports the key in an unencrypted format.</p> + +<p>If the key is sensitive you should use {{DOMxRef("SubtleCrypto.wrapKey","wrapKey()")}}, which exports the key and then encrypts it using another key; the API calls a "key-wrapping key".</p> + +<p>The inverse of <code>wrapKey()</code> is {{DOMxRef("SubtleCrypto.unwrapKey","unwrapKey()")}}, which decrypts then imports the key.</p> + +<h4 id="Storing_keys">Storing keys</h4> + +<p><code>CryptoKey</code> objects can be stored using the <a href="/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm">structured clone algorithm</a>, meaning that you can store and retrieve them using standard web storage APIs. The specification expects that most developers will use the <a href="/en-US/docs/Web/API/IndexedDB_API">IndexedDB API</a> to store <code>CryptoKey</code> objects.</p> + +<h3 id="Supported_algorithms">Supported algorithms</h3> + +<p>The cryptographic functions provided by the Web Crypto API can be performed by one or more different <em>cryptographic algorithms</em>: the <code>algorithm</code> argument to the function indicates which algorithm to use. Some algorithms need extra parameters: in these cases the <code>algorithm</code> argument is a dictionary object that includes the extra parameters.</p> + +<p>The table below summarises which algorithms are suitable for which cryptographic operations:</p> + +<table class="standard-table"> + <thead> + <tr> + <th scope="row"></th> + <th scope="col"> + <p><a href="/en-US/docs/Web/API/SubtleCrypto/sign">sign()</a></p> + + <p><a href="/en-US/docs/Web/API/SubtleCrypto/verify">verify()</a></p> + </th> + <th scope="col"> + <p><a href="/en-US/docs/Web/API/SubtleCrypto/encrypt">encrypt()</a></p> + + <p><a href="/en-US/docs/Web/API/SubtleCrypto/decrypt">decrypt()</a></p> + </th> + <th scope="col"><a href="/en-US/docs/Web/API/SubtleCrypto/digest">digest()</a></th> + <th scope="col"> + <p><a href="/en-US/docs/Web/API/SubtleCrypto/deriveBits">deriveBits()</a></p> + + <p><a href="/en-US/docs/Web/API/SubtleCrypto/deriveKey">deriveKey()</a></p> + </th> + <th scope="col"> + <p><a href="/en-US/docs/Web/API/SubtleCrypto/wrapKey">wrapKey()</a></p> + + <p><a href="/en-US/docs/Web/API/SubtleCrypto/unwrapKey">unwrapKey()</a></p> + </th> + </tr> + </thead> + <tbody> + <tr> + <th scope="row">RSASSA-PKCS1-v1_5</th> + <td>✓</td> + <td></td> + <td></td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">RSA-PSS</th> + <td>✓</td> + <td></td> + <td></td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">ECDSA</th> + <td>✓</td> + <td></td> + <td></td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">HMAC</th> + <td>✓</td> + <td></td> + <td></td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">RSA-OAEP</th> + <td></td> + <td>✓</td> + <td></td> + <td></td> + <td>✓</td> + </tr> + <tr> + <th scope="row">AES-CTR</th> + <td></td> + <td>✓</td> + <td></td> + <td></td> + <td>✓</td> + </tr> + <tr> + <th scope="row">AES-CBC</th> + <td></td> + <td>✓</td> + <td></td> + <td></td> + <td>✓</td> + </tr> + <tr> + <th scope="row">AES-GCM</th> + <td></td> + <td>✓</td> + <td></td> + <td></td> + <td>✓</td> + </tr> + <tr> + <th scope="row">SHA-1</th> + <td></td> + <td></td> + <td>✓</td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">SHA-256</th> + <td></td> + <td></td> + <td>✓</td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">SHA-384</th> + <td></td> + <td></td> + <td>✓</td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">SHA-512</th> + <td></td> + <td></td> + <td>✓</td> + <td></td> + <td></td> + </tr> + <tr> + <th scope="row">ECDH</th> + <td></td> + <td></td> + <td></td> + <td>✓</td> + <td></td> + </tr> + <tr> + <th scope="row">HKDF</th> + <td></td> + <td></td> + <td></td> + <td>✓</td> + <td></td> + </tr> + <tr> + <th scope="row">PBKDF2</th> + <td></td> + <td></td> + <td></td> + <td>✓</td> + <td></td> + </tr> + <tr> + <th scope="row">AES-KW</th> + <td></td> + <td></td> + <td></td> + <td></td> + <td>✓</td> + </tr> + </tbody> +</table> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{ SpecName('Web Crypto API', '#subtlecrypto-interface', 'SubtleCrypto') }}</td> + <td>{{ Spec2('Web Crypto API') }}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.SubtleCrypto")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Web_Crypto_API">Web Crypto API</a></li> + <li><a href="/en-US/docs/Web/Security">Web security</a></li> + <li><a href="/en-US/docs/Web/Privacy">Privacy, permissions, and information security</a></li> + <li>{{domxref("Crypto")}} and {{domxref("Crypto.subtle")}}.</li> + <li><a href="https://www.crypto101.io/">Crypto 101</a>: an introductory course on cryptography.</li> +</ul> |