aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/subtlecrypto
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/fr/web/api/subtlecrypto
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/fr/web/api/subtlecrypto')
-rw-r--r--files/fr/web/api/subtlecrypto/digest/index.html135
-rw-r--r--files/fr/web/api/subtlecrypto/index.html298
2 files changed, 433 insertions, 0 deletions
diff --git a/files/fr/web/api/subtlecrypto/digest/index.html b/files/fr/web/api/subtlecrypto/digest/index.html
new file mode 100644
index 0000000000..091a59de28
--- /dev/null
+++ b/files/fr/web/api/subtlecrypto/digest/index.html
@@ -0,0 +1,135 @@
+---
+title: SubtleCrypto.digest()
+slug: Web/API/SubtleCrypto/digest
+translation_of: Web/API/SubtleCrypto/digest
+---
+<div>{{APIRef("Web Crypto API")}}{{SecureContext_header}}</div>
+
+<p>La méthode <code><strong>digest()</strong></code> de l'interface {{domxref("SubtleCrypto")}} génère un {{Glossary("digest")}} de la donnée fournie. Un condensé est une petite valeur de taille fixe issue d'une donnée de taille variable. Les condensés cryptographiques doivent résister à la collision, ce qui signifie qu'il doit être très difficile d'obtenir le même condensé à partir de deux entrés différentes.</p>
+
+<p>Il prend en argument un identifiant pour l'algorithme de condensé et les données à traiter. Il retourne une {{jsxref("Promise")}} qui contiendra le condensé.</p>
+
+<h2 id="Syntaxe">Syntaxe</h2>
+
+<pre class="syntaxbox notranslate">const digest = <em>crypto</em><code>.subtle.digest(<em>algorithm</em>, <em>data</em>)</code>;
+</pre>
+
+<h3 id="Paramètres">Paramètres</h3>
+
+<ul>
+ <li><em><code>algorithm</code></em> est une {{domxref("DOMString")}} indiquant la fonction de condensé à utiliser. Les valeurs possibles sont:
+
+ <ul>
+ <li><code>SHA-1</code> (ne pas utiliser pour des applications cryptographiques)</li>
+ <li><code>SHA-256</code></li>
+ <li><code>SHA-384</code></li>
+ <li><code>SHA-512</code>.</li>
+ </ul>
+ </li>
+ <li><em><code>data</code></em> est un {{jsxref("ArrayBuffer")}} ou un {{domxref("ArrayBufferView")}} contenant les données à traiter.</li>
+</ul>
+
+<h3 id="Valeur_retournée">Valeur retournée</h3>
+
+<ul>
+ <li><code><em>digest</em></code> est une {{jsxref("Promise")}} pour accéder {{jsxref("ArrayBuffer")}} au condensé.</li>
+</ul>
+
+<h2 id="Algorithmes_supportés">Algorithmes supportés</h2>
+
+<p>Les algorithmes de condensé, aussi connue sous le nom de <a href="/fr/docs/Glossaire/Fonction_de_hachage_cryptographique">fonctions de hachage cryptographique</a>, transforme un bloque de données de longueur arbitraire dans un résultat de taille fixe, souvent plus petit que l'entré. Ils ont de nombreuses utilisations en cryptographie.</p>
+
+<h3 id="SHA-1">SHA-1</h3>
+
+<p>Cet algorithme est spécifié dans <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf">FIPS 180-4</a>, section 6.1, et produit un résultat de 160 bits de long.</p>
+
+<div class="blockIndicator warning">
+<p><strong>Avertissement:</strong> Cet algorithme est maintenant considérer comme vulnérable et ne doit pas être utilisé pour des applications cryptographiques.</p>
+</div>
+
+<h3 id="SHA-256">SHA-256</h3>
+
+<p>Cet algorithme est spécifié dans <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf">FIPS 180-4</a>, section 6.2, et produit un résultat de 256 bits de long.</p>
+
+<h3 id="SHA-384">SHA-384</h3>
+
+<p>Cet algorithme est spécifié dans <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf">FIPS 180-4</a>, section 6.5, et produit un résultat de 384 bits de long.</p>
+
+<h3 id="SHA-512">SHA-512</h3>
+
+<p>Cet algorithme est spécifié dans <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf">FIPS 180-4</a>, section 6.4, et produit un résultat de 512 bits de long.</p>
+
+<div class="blockIndicator note">
+<p>Indice: Si vous cherchez à créer un condensé pour authentifié un message (<a href="/fr/docs/Glossary/HMAC">HMAC</a>), vous aurez plutôt besoin de <a href="/en-US/docs/Web/API/SubtleCrypto/sign#HMAC">SubtleCrypto.sign()</a>.</p>
+</div>
+
+<h2 id="Exemples">Exemples</h2>
+
+<h3 id="Exemple_basique">Exemple basique</h3>
+
+<p>Cet exemple encode un message, puis calcule le condensé avec SHA-256, enfin affiche la longueur du résultat.</p>
+
+<pre class="brush: js notranslate">const text = 'Un obscur message venant du le système S-K, votre majesté. Ses habitants le nomment la planète Terre.';
+
+async function digestMessage(message) {
+ const encoder = new TextEncoder();
+ const data = encoder.encode(message);
+ const hash = await crypto.subtle.digest('SHA-256', data);
+ return hash;
+}
+
+const digestBuffer = await digestMessage(text);
+console.log(digestBuffer.byteLength);
+</pre>
+
+<h3 id="Convertir_un_condensé_vers_une_chaîne_hexadécimale">Convertir un condensé vers une chaîne hexadécimale</h3>
+
+<p>Le condensé est retourné sous forme d'un <code>ArrayBuffer</code>, mais la comparaison et l'affichage se fait souvent avec des chaînes hexadécimales. Cet exemple calcule un condensé puis converti l'<code>ArrayBuffer</code> vers une chaîne hexadécimale.</p>
+
+<pre class="brush: js notranslate">const text = 'Un obscur message venant du le système S-K, votre majesté. Ses habitants le nomment la planète Terre.';
+
+async function digestMessage(message) {
+ const msgUint8 = new TextEncoder().encode(message); // encode comme (utf-8) Uint8Array
+ const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // fait le condensé
+ const hashArray = Array.from(new Uint8Array(hashBuffer)); // convertit le buffer en tableau d'octet
+ const hashHex = hashArray.map(b =&gt; b.toString(16).padStart(2, '0')).join(''); // convertit le tableau en chaîne hexadélimale
+ return hashHex;
+}
+
+const digestHex = await digestMessage(text);
+console.log(digestHex);
+</pre>
+
+<h2 id="Spécifications">Spécifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Spécifications</th>
+ <th scope="col">Statue</th>
+ <th scope="col">Commentaire</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Web Crypto API', '#dfn-SubtleCrypto-method-digest', 'SubtleCrypto.digest()')}}</td>
+ <td>{{Spec2('Web Crypto API')}}</td>
+ <td>Définition intiale</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>
+
+
+
+<p>{{Compat("api.SubtleCrypto.digest")}}</p>
+
+<div class="blockIndicator note">
+<p> Dans Chrome 60, une fonctionnalité a été ajoutée qui désactive <strong>crypto.subtle</strong> pour les connexions non TLS.</p>
+</div>
+
+<h2 id="Voir_aussi">Voir aussi</h2>
+
+<ul>
+ <li><a href="https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features">(en) Chromium secure origins specification</a></li>
+ <li><a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf" rel="noopener">(en) FIPS 180-4</a> spécifie les algorithmes de condensé de la famille SHA.</li>
+</ul>
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>