Skip to content

Commit c40f42d

Browse files
authored
docs(review): review of en/decrypting data with asym key
1 parent a1e3d8f commit c40f42d

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

pages/key-manager/api-cli/encrypt-decrypt-asymmetric-key-with-go-sdk.mdx

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
h1: Encrypting and decrypting data with an asymmetric key
2-
paragraph: Learn how to encrypt and decrypt data with an asymmetric key using Key Manager with Scaleway Go SDK.
1+
---
2+
meta:
3+
title: Encrypting and decrypting data with an asymmetric key
4+
description: Learn how to encrypt and decrypt data with an asymmetric key using Key Manager and the Scaleway Go SDK.
5+
content:
6+
h1: Encrypting and decrypting data with an asymmetric key
7+
paragraph: Learn how to encrypt and decrypt data with an asymmetric key using Key Manager and the Scaleway Go SDK.
38
tags: key sensitive-data encrypt decrypt asymmetric digest
49
dates:
5-
validation: 2025-02-06
6-
posted: 2025-02-06
10+
validation: 2025-05-27
11+
posted: 2025-05-27
712
---
813

9-
Scaleway's Key Manager provides a secure way to manage asymmetric keys, allowing you to offload sensitive cryptographic
10-
operations to a managed service. In this guide, you'll learn how to integrate the Scaleway Go SDK to encrypt and decrypt
11-
data using an rsa_oaep_3072_sha256 key directly through the Key Manager API.
14+
Scaleway's Key Manager provides a secure way to manage asymmetric keys, allowing you to offload sensitive cryptographic operations to a managed service. This documentation page shows you how to integrate the Scaleway Go SDK to encrypt and decrypt data using an `rsa_oaep_3072_sha256` key directly through the [Key Manager API](https://www.scaleway.com/en/developers/api/key-manager/).
1215

1316

14-
<Message type="warning">
15-
Please note that we do not recommend using asymmetric encryption for anything other than key encryption.
16-
For all other purposes (eg. encrypting large data or files), we recommend using Tink with Scaleway's Key Manager as explained [here.](/key-manager/api-cli/encrypt-decrypt-data-with-km-dek/)
17+
<Message type="important">
18+
We do not recommend using asymmetric encryption for anything other than key encryption.
19+
For all other purposes (encrypting large data or files), we recommend using Tink with Scaleway's Key Manager as explained [in the dedicated documentation](/key-manager/api-cli/encrypt-decrypt-data-with-km-dek/).
1720
</Message>
1821

1922
## Configuring your environment variables
@@ -30,16 +33,15 @@ Open a terminal and paste the following commands to export your environment vari
3033
export SCW_API_URL="<api-URL>"
3134
```
3235

33-
## Encrypt data
36+
## Encrypting data
3437

35-
This operation takes place locally, ensuring the plaintext message never leaves your environment unprotected.
36-
The public key can be fetched using the Key Manager API, parsed, and used to encrypt data with RSA-OAEP and SHA-256 padding.
38+
This operation takes place locally, ensuring the plaintext message never leaves your environment unprotected. The public key can be fetched using the Key Manager API, parsed, and used to encrypt data with RSA-OAEP and SHA-256 padding.
3739

3840
```golang
39-
// encryptAsymmetric encrypts data on your local machine using an 'rsa_oaep_3072_sha256' key retrieved from Scaleway KMS.
41+
// encryptAsymmetric encrypts data on your local machine using an 'rsa_oaep_3072_sha256' key retrieved from Scaleway Key Manager.
4042
//
4143
// Parameters:
42-
// - keyID: The unique identifier of the asymmetric key stored in Scaleway KMS.
44+
// - keyID: The unique identifier of the asymmetric key stored in Key Manager.
4345
// - message: The plaintext message that needs to be encrypted.
4446
//
4547
// Returns:
@@ -52,15 +54,15 @@ func encryptAsymmetric(keyID string, message string) error {
5254
}
5355
kmsApi := key_manager.NewAPI(client)
5456

55-
// Retrieve the public key from Scaleway KMS.
57+
// Retrieve the public key from Key Manager.
5658
response, err := kmsApi.GetPublicKey(&key_manager.GetPublicKeyRequest{
5759
KeyID: keyID,
5860
})
5961
if err != nil {
6062
return fmt.Errorf("failed to get public key: %w", err)
6163
}
6264

63-
// Parse the public key. Note, this example assumes the public key is in the
65+
// Parse the public key. This example assumes the public key is in the
6466
// RSA format.
6567
block, _ := pem.Decode([]byte(response.Pem))
6668
publicKey, err := x509.ParsePKCS1PublicKey(block.Bytes)
@@ -84,23 +86,24 @@ func encryptAsymmetric(keyID string, message string) error {
8486
```
8587

8688
<Message type="note">
87-
Please note that :
88-
- Encryption can also be performed using the Scaleway's Key Manager Encrypt method.
89-
- In the case of asymmetric encryption, the maximum payload size allowed depends on the key algo (190 bytes for `RSA_OAEP_2048_SHA256`, 318 bytes for `RSA_OAEP_3072_SHA256` and 446 bytes for `RSA_OAEP_4096_SHA256`).
89+
- Encryption can also be performed using the [encrypt method of the Key Manager API](https://www.scaleway.com/en/developers/api/key-manager/#path-keys-encrypt-a-payload).
90+
- For asymmetric encryption, the maximum payload size allowed depends on the key algorithm used:
91+
- 190 bytes for `RSA_OAEP_2048_SHA256`
92+
- 318 bytes for `RSA_OAEP_3072_SHA256` and
93+
- 446 bytes for `RSA_OAEP_4096_SHA256`)
9094
</Message>
9195

92-
## Decrypt data
96+
## Decrypting data
9397

94-
To retrieve the original message, you must send the encrypted ciphertext to Scaleway Key Manager,
95-
which uses the private portion of the asymmetric key to decrypt it. This ensures your private key remains secure within
98+
To retrieve the original message, you must send the encrypted ciphertext to Scaleway Key Manager, which uses the private portion of the asymmetric key to decrypt it. This ensures your private key remains secure within
9699
Scaleway’s infrastructure.
97100

98101
```golang
99102

100-
// decryptAsymmetric attempts to decrypt a given ciphertext using an 'rsa_oaep_3072_sha256' key from Scaleway KMS.
103+
// decryptAsymmetric attempts to decrypt a given ciphertext using an 'rsa_oaep_3072_sha256' key from Key Manager.
101104
//
102105
// Parameters:
103-
// - keyID: The unique identifier of the asymmetric key stored in Scaleway KMS.
106+
// - keyID: The unique identifier of the asymmetric key stored in Key Manager.
104107
// - ciphertext: The encrypted data that needs to be decrypted.
105108
//
106109
// Returns:
@@ -128,4 +131,4 @@ func decryptAsymmetric(keyID string, ciphertext []byte) error {
128131
fmt.Printf("Decrypted plaintext: %s", result.Plaintext)
129132
return nil
130133
}
131-
```
134+
```

0 commit comments

Comments
 (0)