Keyring non elaborati AES - AWS Encryption SDK

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Keyring non elaborati AES

Ti AWS Encryption SDK consente di utilizzare una chiave simmetrica AES fornita come chiave di wrapping per proteggere la tua chiave dati. È necessario generare, archiviare e proteggere il materiale chiave, preferibilmente in un modulo di sicurezza hardware (HSM) o in un sistema di gestione delle chiavi. Usa un portachiavi Raw AES quando devi fornire la chiave di wrapping e crittografare le chiavi dati localmente o offline.

Il portachiavi Raw AES crittografa i dati utilizzando l'algoritmo AES-GCM e una chiave di wrapping specificata come array di byte. È possibile specificare solo una chiave di avvolgimento in ogni portachiavi Raw AES, ma è possibile includere più portachiavi Raw AES, da soli o con altri portachiavi, in un portachiavi multiplo.

Il portachiavi Raw AES è equivalente e interagisce con la JceMasterKeyclasse in e con la classe in SDK di crittografia AWS per Python quando viene SDK di crittografia AWS per Java utilizzato con una chiave di crittografia AES. RawMasterKey È possibile crittografare e decrittare i dati con implementazioni diverse, ma utilizzando la stessa chiave di wrapping. Per informazioni dettagliate, consultare Compatibilità dei keyring.

Namespace e nomi chiave

Per identificare la chiave AES in un portachiavi, il portachiavi Raw AES utilizza uno spazio dei nomi e un nome chiave forniti dall'utente. Questi valori non sono segreti. Vengono visualizzati in testo semplice nell'intestazione del messaggio crittografato restituito dall'operazione di crittografia. Si consiglia di utilizzare uno spazio dei nomi delle chiavi (HSM o sistema di gestione delle chiavi) e un nome di chiave che identifichi la chiave AES in quel sistema.

Nota

Lo spazio dei nomi e il nome della chiave sono equivalenti ai campi Provider ID (o Provider) e Key ID presenti nel e. JceMasterKey RawMasterKey

SDK di crittografia AWS per C and AWS Encryption SDK for .NET riserva il valore dello spazio dei nomi aws-kms chiave per le chiavi KMS. Non utilizzare questo valore dello spazio dei nomi in un portachiavi Raw AES o Raw RSA con queste librerie.

Se si creano portachiavi diversi per crittografare e decrittografare un determinato messaggio, lo spazio dei nomi e i valori del nome sono fondamentali. Se lo spazio dei nomi della chiave e il nome della chiave nel portachiavi di decrittografia non corrispondono esattamente, con distinzione tra maiuscole e minuscole, per lo spazio dei nomi della chiave e il nome della chiave nel portachiavi di crittografia, il portachiavi di decrittografia non viene utilizzato, anche se i byte del materiale della chiave sono identici.

Ad esempio, è possibile definire un portachiavi Raw AES con lo spazio dei nomi e il nome della chiave. HSM_01 AES_256_012 Quindi, usi quel portachiavi per crittografare alcuni dati. Per decrittografare quei dati, crea un portachiavi Raw AES con lo stesso spazio dei nomi delle chiavi, nome chiave e materiale chiave.

I seguenti esempi mostrano come creare un portachiavi Raw AES. La AESWrappingKey variabile rappresenta il materiale chiave fornito.

C

Per creare un'istanza di un portachiavi Raw AES in, usa. SDK di crittografia AWS per Caws_cryptosdk_raw_aes_keyring_new() Per un esempio completo, vedete raw_aes_keyring.c.

struct aws_allocator *alloc = aws_default_allocator(); AWS_STATIC_STRING_FROM_LITERAL(wrapping_key_namespace, "HSM_01"); AWS_STATIC_STRING_FROM_LITERAL(wrapping_key_name, "AES_256_012"); struct aws_cryptosdk_keyring *raw_aes_keyring = aws_cryptosdk_raw_aes_keyring_new( alloc, wrapping_key_namespace, wrapping_key_name, aes_wrapping_key, wrapping_key_len);
C# / .NET

Per creare un portachiavi Raw AES in.NET, usa il metodo. AWS Encryption SDK materialProviders.CreateRawAesKeyring() Per un esempio completo, vedete Raw AESKeyring Example.cs.

L'esempio seguente utilizza la versione 4. x del AWS Encryption SDK per .NET.

// Instantiate the AWS Encryption SDK and material providers var esdk = new ESDK(new AwsEncryptionSdkConfig()); var mpl = new MaterialProviders(new MaterialProvidersConfig()); var keyNamespace = "HSM_01"; var keyName = "AES_256_012"; // This example uses the key generator in Bouncy Castle to generate the key material. // In production, use key material from a secure source. var aesWrappingKey = new MemoryStream(GeneratorUtilities.GetKeyGenerator("AES256").GenerateKey()); // Create the keyring that determines how your data keys are protected. var createKeyringInput = new CreateRawAesKeyringInput { KeyNamespace = keyNamespace, KeyName = keyName, WrappingKey = aesWrappingKey, WrappingAlg = AesWrappingAlg.ALG_AES256_GCM_IV12_TAG16 }; var keyring = materialProviders.CreateRawAesKeyring(createKeyringInput);
JavaScript Browser

SDK di crittografia AWS per JavaScript Nel browser ottiene le sue primitive crittografiche dall'API. WebCrypto Prima di costruire il portachiavi, è necessario RawAesKeyringWebCrypto.importCryptoKey() importare il materiale grezzo della chiave nel backend. WebCrypto Ciò garantisce che il portachiavi sia completo anche se tutte le chiamate a sono asincrone. WebCrypto

Quindi, per creare un'istanza di un portachiavi Raw AES, usa il metodo. RawAesKeyringWebCrypto() È necessario specificare l'algoritmo di wrapping AES («wrapping suite») in base alla lunghezza del materiale chiave. Per un esempio completo, vedete aes_simple.ts (Browser). JavaScript

L'esempio seguente utilizza la buildClient funzione per specificare la politica di impegno predefinita,. REQUIRE_ENCRYPT_REQUIRE_DECRYPT È inoltre possibile utilizzare il buildClient per limitare il numero di chiavi di dati crittografate in un messaggio crittografato. Per ulteriori informazioni, consulta Limitazione delle chiavi dati crittografate.

import { RawAesWrappingSuiteIdentifier, RawAesKeyringWebCrypto, synchronousRandomValues, buildClient, CommitmentPolicy, } from '@aws-crypto/client-browser' const { encrypt, decrypt } = buildClient( CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT ) const keyNamespace = 'HSM_01' const keyName = 'AES_256_012' const wrappingSuite = RawAesWrappingSuiteIdentifier.AES256_GCM_IV12_TAG16_NO_PADDING /* Import the plaintext AES key into the WebCrypto backend. */ const aesWrappingKey = await RawAesKeyringWebCrypto.importCryptoKey( rawAesKey, wrappingSuite ) const rawAesKeyring = new RawAesKeyringWebCrypto({ keyName, keyNamespace, wrappingSuite, aesWrappingKey })
JavaScript Node.js

Per creare un'istanza di un portachiavi Raw AES in SDK di crittografia AWS per JavaScript for Node.js, create un'istanza della classe. RawAesKeyringNode È necessario specificare l'algoritmo di wrapping AES («wrapping suite») in base alla lunghezza del materiale chiave. Per un esempio completo, vedete aes_simple.ts (Node.js). JavaScript

L'esempio seguente utilizza la buildClient funzione per specificare la politica di impegno predefinita,. REQUIRE_ENCRYPT_REQUIRE_DECRYPT È inoltre possibile utilizzare il buildClient per limitare il numero di chiavi di dati crittografate in un messaggio crittografato. Per ulteriori informazioni, consulta Limitazione delle chiavi dati crittografate.

import { RawAesKeyringNode, buildClient, CommitmentPolicy, RawAesWrappingSuiteIdentifier, } from '@aws-crypto/client-node' const { encrypt, decrypt } = buildClient( CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT ) const keyName = 'AES_256_012' const keyNamespace = 'HSM_01' const wrappingSuite = RawAesWrappingSuiteIdentifier.AES256_GCM_IV12_TAG16_NO_PADDING const rawAesKeyring = new RawAesKeyringNode({ keyName, keyNamespace, aesWrappingKey, wrappingSuite, })
Java

Per creare un'istanza di un portachiavi Raw AES in, usa. SDK di crittografia AWS per JavamatProv.CreateRawAesKeyring()

final CreateRawAesKeyringInput keyringInput = CreateRawAesKeyringInput.builder() .keyName("AES_256_012") .keyNamespace("HSM_01") .wrappingKey(AESWrappingKey) .wrappingAlg(AesWrappingAlg.ALG_AES256_GCM_IV12_TAG16) .build(); final MaterialProviders matProv = MaterialProviders.builder() .MaterialProvidersConfig(MaterialProvidersConfig.builder().build()) .build(); IKeyring rawAesKeyring = matProv.CreateRawAesKeyring(keyringInput);
Python

L'esempio seguente crea un'istanza del AWS Encryption SDK client con la politica di impegno predefinita,. REQUIRE_ENCRYPT_REQUIRE_DECRYPT Per un esempio completo, vedere raw_aes_keyring_example.py nel SDK di crittografia AWS per Python repository in. GitHub

# Instantiate the AWS Encryption SDK client client = aws_encryption_sdk.EncryptionSDKClient( commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT ) # Define the key namespace and key name key_name_space = "HSM_01" key_name = "AES_256_012" # Optional: Create an encryption context encryption_context: Dict[str, str] = { "encryption": "context", "is not": "secret", "but adds": "useful metadata", "that can help you": "be confident that", "the data you are handling": "is what you think it is", } # Instantiate the material providers mat_prov: AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders( config=MaterialProvidersConfig() ) # Create Raw AES keyring keyring_input: CreateRawAesKeyringInput = CreateRawAesKeyringInput( key_namespace=key_name_space, key_name=key_name, wrapping_key=AESWrappingKey, wrapping_alg=AesWrappingAlg.ALG_AES256_GCM_IV12_TAG16 ) raw_aes_keyring: IKeyring = mat_prov.create_raw_aes_keyring( input=keyring_input )
Rust
// Instantiate the AWS Encryption SDK client let esdk_config = AwsEncryptionSdkConfig::builder().build()?; let esdk_client = esdk_client::Client::from_conf(esdk_config)?; // Define the key namespace and key name let key_namespace: &str = "HSM_01"; let key_name: &str = "AES_256_012"; // Optional: Create an encryption context let encryption_context = HashMap::from([ ("encryption".to_string(), "context".to_string()), ("is not".to_string(), "secret".to_string()), ("but adds".to_string(), "useful metadata".to_string()), ("that can help you".to_string(), "be confident that".to_string()), ("the data you are handling".to_string(), "is what you think it is".to_string()), ]); // Instantiate the material providers library let mpl_config = MaterialProvidersConfig::builder().build()?; let mpl = mpl_client::Client::from_conf(mpl_config)?; // Create Raw AES keyring let raw_aes_keyring = mpl .create_raw_aes_keyring() .key_name(key_name) .key_namespace(key_namespace) .wrapping_key(aws_smithy_types::Blob::new(AESWrappingKey)) .wrapping_alg(AesWrappingAlg::AlgAes256GcmIv12Tag16) .send() .await?;
Go
import ( mpl "aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygenerated" mpltypes "aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygeneratedtypes" client "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygenerated" esdktypes "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygeneratedtypes" ) //Instantiate the AWS Encryption SDK client. encryptionClient, err := client.NewClient(esdktypes.AwsEncryptionSdkConfig{}) if err != nil { panic(err) } // Define the key namespace and key name var keyNamespace = "A managed aes keys" var keyName = "My 256-bit AES wrapping key" // Optional: Create an encryption context encryptionContext := map[string]string{ "encryption": "context", "is not": "secret", "but adds": "useful metadata", "that can help you": "be confident that", "the data you are handling": "is what you think it is", } // Instantiate the material providers library matProv, err := mpl.NewClient(mpltypes.MaterialProvidersConfig{}) if err != nil { panic(err) } // Create Raw AES keyring aesKeyRingInput := mpltypes.CreateRawAesKeyringInput{ KeyName: keyName, KeyNamespace: keyNamespace, WrappingKey: aesWrappingKey, WrappingAlg: mpltypes.AesWrappingAlgAlgAes256GcmIv12Tag16, } aesKeyring, err := matProv.CreateRawAesKeyring(context.Background(), aesKeyRingInput) if err != nil { panic(err) }