# CSP (Microsoft Crypto API)

O padrão/protocolo Microsoft CryptoAPI é amplamente utilizado por aplicações que utilizam operações criptográficas com chaves **não** exportáveis, o protocolo define uma especificação padronizada para interação com hardwares criptográficos (Smartcards, Tokens e HSMs) o suporte é oferecido pela maioria dos fabricantes de hardware no segmento, no cenário do uso de certificado em nuvem é utilizado principalmente para autenticação, listagem de objetos e assinatura. O driver fornecido pela plataforma é utilizado integrando recursos diretamente do repositório de certificados disponível no Microsoft Windows.

A MSCAPI é uma biblioteca nativa nas plataformas Microsoft Windows que oferece compatibilidade com as melhores bibliotecas de criptografia para windows, possibilitando uma integração rápida e garantindo uma interoperabilidade na solução que está sendo integrada.

Também já funciona para uso final em aplicações que já utilizam certificados do tipo A3. Como o protocolo também faz parte dos requisitos técnicos no processo de homologação de hardwares (tokens/smartcards) no âmbito da ICP Brasil ([DOC-ICP-10.05 2.1-b](https://www.iti.gov.br/images/repositorio/legislacao/documentos-principais/10.5/DOC-ICP-10.05_-_v_1.0.pdf)) muitas aplicações já suportam o uso em sua versão nativa, não demandando nenhuma integração adicional para a utilização do certificado em nuvem.

### Instalação <a href="#instalacao" id="instalacao"></a>

#### Windows: <a href="#windows" id="windows"></a>

#### Linux: <a href="#linux" id="linux"></a>

#### Mac OSx: <a href="#mac-osx" id="mac-osx"></a>

### Binários <a href="#binarios" id="binarios"></a>

#### Windows: <a href="#windows-1" id="windows-1"></a>

#### Linux: <a href="#linux-1" id="linux-1"></a>

#### Mac OSx: <a href="#mac-osx-1" id="mac-osx-1"></a>

### Funções disponíveis <a href="#funcoes-disponiveis" id="funcoes-disponiveis"></a>

**Status classification**

| Type  | Description             |
| ----- | ----------------------- |
| OK    | Feature implemented     |
| QUEUE | Implementation queue    |
| x     | Will not be implemented |

***Service Provider Functions***

Applications use the following service functions to connect and disconnect a [*cryptographic service provider*](https://docs.microsoft.com/en-us/windows/desktop/seccrypto/cryptographic-service-providers) (CSP).

| Status | Category            | Description                                                                                                                                                             |
| ------ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| OK     | CryptAcquireContext | Acquires a handle to the current user's [*key container*](https://docs.microsoft.com/windows/desktop/SecGloss/k-gly) within a particular CSP.                           |
| OK     | CryptReleaseContext | Releases the handle acquired by the [**CryptAcquireContext**](https://docs.microsoft.com/en-us/windows/desktop/api/Wincrypt/nf-wincrypt-cryptacquirecontexta) function. |
| x      | CryptGenKey         | Creates a random key.                                                                                                                                                   |
| x      | CryptDeriveKey      | Creates a key derived from a password.                                                                                                                                  |
| OK     | CryptGetUserKey     | Gets a handle to the key exchange or signature key.                                                                                                                     |
| OK     | CryptDestroyKey     | Destroys a key.                                                                                                                                                         |
| OK     | CryptSetKeyParam    | Specifies a key's parameters.                                                                                                                                           |
| OK     | CryptGetKeyParam    | Retrieves a key's parameters.                                                                                                                                           |
| x      | CryptSetProvParam   | Specifies attributes of a CSP.                                                                                                                                          |
| OK     | CryptGetProvParam   | Retrieves the parameters that govern the operations of a CSP.                                                                                                           |
| OK     | CryptSetHashParam   | Sets a hash object parameter.                                                                                                                                           |
| OK     | CryptGetHashParam   | Retrieves a hash object parameter.                                                                                                                                      |
| QUEUE  | CryptExportKey      | Transfers a key from the CSP into a [*key BLOB*](https://docs.microsoft.com/windows/desktop/SecGloss/k-gly) in the application's memory space.                          |
| x      | CryptImportKey      | Transfers a key from a [*key BLOB*](https://docs.microsoft.com/windows/desktop/SecGloss/k-gly) to a CSP.                                                                |

**Data Encryption and Decryption Functions**

| Status | Category     | Description                                                                                                                            |
| ------ | ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| x      | CryptEncrypt | Encrypts a section of [*plaintext*](https://docs.microsoft.com/windows/desktop/SecGloss/p-gly) by using the specified encryption key.  |
| x      | CryptDecrypt | Decrypts a section of [*ciphertext*](https://docs.microsoft.com/windows/desktop/SecGloss/c-gly) by using the specified encryption key. |

**Hash and Digital Signature Functions**

| Status | Category             | Description                                                                                                                  |
| ------ | -------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| OK     | CryptCreateHash      | Creates an empty hash object.                                                                                                |
| OK     | CryptHashData        | Hashes a block of data, adding it to the specified hash object.                                                              |
| x      | CryptHashSessionKey  | Hashes a session key, adding it to the specified hash object.                                                                |
| OK     | CryptSignHash        | Signs the specified hash object.                                                                                             |
| x      | CryptVerifySignature | Verifies a digital signature, given a handle to the hash object.                                                             |
| OK     | CryptDestroyHash     | Destroys a hash object.                                                                                                      |
| x      | CryptGenRandom       | Generates random data.                                                                                                       |
| OK     | CryptDuplicateHash   | Duplicates a hash object.                                                                                                    |
| x      | CryptDuplicateKey    | Makes an exact copy of a key, including the [*state*](https://docs.microsoft.com/windows/desktop/SecGloss/s-gly) of the key. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.vaultid.com.br/workspace/middleware/csp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
