From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/fr/web/api/subtlecrypto/index.html | 298 +++++++++++++++++++++++++++++++ 1 file changed, 298 insertions(+) create mode 100644 files/fr/web/api/subtlecrypto/index.html (limited to 'files/fr/web/api/subtlecrypto/index.html') 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 +--- +
{{APIRef("Web Crypto API")}}{{SecureContext_header}}
+ +

The SubtleCrypto interface of the Web Crypto API provides a number of low-level cryptographic functions. Access to the features of SubtleCrypto is obtained through the {{domxref("Crypto.subtle", "subtle")}} property of the {{domxref("Crypto")}} object you get from {{domxref("Window.crypto")}}.

+ +
+

Warning: 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.

+ +

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.

+ +

Errors in security system design and implementation can make the security of the system completely ineffective.

+ +

If you're not sure you know what you are doing, you probably shouldn't be using this API.

+
+ +

Properties

+ +

This interface doesn't inherit any properties, as it has no parent interface.

+ +

Methods

+ +

This interface doesn't inherit any methods, as it has no parent interface.

+ +
+
{{domxref("SubtleCrypto.encrypt()")}}
+
Returns a {{jsxref("Promise")}} that fufills with the encrypted data corresponding to the clear text, algorithm, and key given as parameters.
+
{{domxref("SubtleCrypto.decrypt()")}}
+
Returns a {{jsxref("Promise")}} that fulfills with the clear data corresponding to the encrypted text, algorithm, and key given as parameters.
+
{{domxref("SubtleCrypto.sign()")}}
+
Returns a {{jsxref("Promise")}} that fulfills with the signature corresponding to the text, algorithm, and key given as parameters.
+
{{domxref("SubtleCrypto.verify()")}}
+
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.
+
{{domxref("SubtleCrypto.digest()")}}
+
Returns a {{jsxref("Promise")}} that fulfills with a digest generated from the algorithm and text given as parameters.
+
{{domxref("SubtleCrypto.generateKey()")}}
+
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.
+
{{domxref("SubtleCrypto.deriveKey()")}}
+
Returns a {{jsxref("Promise")}} that fulfills with a newly generated {{domxref("CryptoKey")}} derived from the master key and specific algorithm given as parameters.
+
{{domxref("SubtleCrypto.deriveBits()")}}
+
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.
+
{{domxref("SubtleCrypto.importKey()")}}
+
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.
+
{{domxref("SubtleCrypto.exportKey()")}}
+
Returns a {{jsxref("Promise")}} that fulfills with a buffer containing the key in the requested format.
+
{{domxref("SubtleCrypto.wrapKey()")}}
+
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.
+
{{domxref("SubtleCrypto.unwrapKey()")}}
+
Returns a {{jsxref("Promise")}} that fulfills with a {{domxref("CryptoKey")}} corresponding to the wrapped key given in the parameter.
+
+ +

Using SubtleCrypto

+ +

We can split the functions implemented by this API into two groups: cryptography functions and key management functions.

+ +

Cryptography functions

+ +

These are the functions you can use to implement security features such as privacy and authentication in a system. The SubtleCrypto API provides the following cryptography functions:

+ +

* {{DOMxRef("SubtleCrypto.sign","sign()")}} and {{DOMxRef("SubtleCrypto.verify","verify()")}}: create and verify digital signatures.
+ * {{DOMxRef("SubtleCrypto.encrypt","encrypt()")}} and {{DOMxRef("SubtleCrypto.decrypt","decrypt()")}}: encrypt and decrypt data.
+ * {{DOMxRef("SubtleCrypto.digest","digest()")}}: create a fixed-length, collision-resistant digest of some data.

+ +

Key management functions

+ +

Except for {{DOMxRef("SubtleCrypto.digest","digest()")}}, all the cryptography functions in the API use cryptographic keys. In the SubtleCrypto 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.

+ +

Generating and deriving keys

+ +

The {{DOMxRef("SubtleCrypto.generateKey","generateKey()")}} and {{DOMxRef("SubtleCrypto.deriveKey","deriveKey()")}} functions both create a new {{DOMxRef("CryptoKey")}} object.

+ +

The difference is that generateKey() will generate a new distinct key value each time you call it, while deriveKey() derives a key from some initial keying material. If you provide the same keying material to two separate calls to deriveKey(), you will get two CryptoKey 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.

+ +

Importing and exporting keys

+ +

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.

+ +

The inverse of exportKey() is {{DOMxRef("SubtleCrypto.importKey","importKey()")}}. You can import keys from other systems, and support for standard formats like PKCS #8 and JSON Web Key helps you do this. The exportKey() function exports the key in an unencrypted format.

+ +

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".

+ +

The inverse of wrapKey() is {{DOMxRef("SubtleCrypto.unwrapKey","unwrapKey()")}}, which decrypts then imports the key.

+ +

Storing keys

+ +

CryptoKey objects can be stored using the structured clone algorithm, meaning that you can store and retrieve them using standard web storage APIs. The specification expects that most developers will use the IndexedDB API to store CryptoKey objects.

+ +

Supported algorithms

+ +

The cryptographic functions provided by the Web Crypto API can be performed by one or more different cryptographic algorithms: the algorithm argument to the function indicates which algorithm to use. Some algorithms need extra parameters: in these cases the algorithm argument is a dictionary object that includes the extra parameters.

+ +

The table below summarises which algorithms are suitable for which cryptographic operations:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

sign()

+ +

verify()

+
+

encrypt()

+ +

decrypt()

+
digest() +

deriveBits()

+ +

deriveKey()

+
+

wrapKey()

+ +

unwrapKey()

+
RSASSA-PKCS1-v1_5
RSA-PSS
ECDSA
HMAC
RSA-OAEP
AES-CTR
AES-CBC
AES-GCM
SHA-1
SHA-256
SHA-384
SHA-512
ECDH
HKDF
PBKDF2
AES-KW
+ +

Specifications

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{ SpecName('Web Crypto API', '#subtlecrypto-interface', 'SubtleCrypto') }}{{ Spec2('Web Crypto API') }}Initial definition.
+ +

Browser compatibility

+ + + +

{{Compat("api.SubtleCrypto")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf