- C
-
で Raw AES キーリングをインスタンス化するには AWS Encryption SDK for C、 を使用しますaws_cryptosdk_raw_aes_keyring_new()
。完全な例については、「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
-
for .NET で Raw AES AWS Encryption SDK キーリングを作成するには、 materialProviders.CreateRawAesKeyring()
メソッドを使用します。完全な例については、「RawAESKeyringExample.cs」を参照してください。
次の例では、.NET 用 AWS Encryption SDK のバージョン 4.x を使用します。
// 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
-
ブラウザ AWS Encryption SDK for JavaScript の はWebCrypto API から暗号化プリミティブを取得します。キーリングを作成する前に、RawAesKeyringWebCrypto.importCryptoKey()
を使用して Raw キーマテリアルを WebCrypto バックエンドにインポートする必要があります。これにより、WebCrypto へのすべての呼び出しが非同期であっても、キーリングが完成することが保証されます。
次に、Raw AES キーリングをインスタンス化するには、RawAesKeyringWebCrypto()
メソッドを使用します。キーマテリアルの長さに基づいて AES ラッピングアルゴリズム (「ラッピングスイート」) を指定する必要があります。完全な例については、「aes_simple.ts (JavaScript ブラウザー)」を参照してください。
次の例では、 buildClient
関数を使用してデフォルトのコミットメントポリシー を指定しますREQUIRE_ENCRYPT_REQUIRE_DECRYPT
。を使用してbuildClient
、暗号化されたメッセージ内の暗号化されたデータキーの数を制限することもできます。詳細については、「暗号化されたデータキーの制限」を参照してください。
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
-
Node.js AWS Encryption SDK for JavaScript の で Raw AES キーリングをインスタンス化するには、 RawAesKeyringNode
クラスのインスタンスを作成します。キーマテリアルの長さに基づいて AES ラッピングアルゴリズム (「ラッピングスイート」) を指定する必要があります。完全な例については、「aes_simple.ts (JavaScript Node.js)」を参照してください。
次の例では、 buildClient
関数を使用してデフォルトのコミットメントポリシー を指定しますREQUIRE_ENCRYPT_REQUIRE_DECRYPT
。を使用してbuildClient
、暗号化されたメッセージ内の暗号化されたデータキーの数を制限することもできます。詳細については、「暗号化されたデータキーの制限」を参照してください。
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
-
で Raw AES キーリングをインスタンス化するには AWS Encryption SDK for Java、 を使用しますmatProv.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
-
次の例では、デフォルトのコミットメントポリシー を使用して AWS Encryption SDK クライアントをインスタンス化しますREQUIRE_ENCRYPT_REQUIRE_DECRYPT
。完全な例については、GitHub の AWS Encryption SDK for Python リポジトリの「raw_aes_keyring_example.py」を参照してください。
# 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)
}