예제 #1
0
        private static async Task <string> CreateKey(KmsManagementClient kmsManagementClient, string compartmentId)
        {
            logger.Info("Creating Key");

            KeyShape keyShape = new KeyShape
            {
                Algorithm = KeyShape.AlgorithmEnum.Aes,
                Length    = DefaultKeyLength
            };
            CreateKeyDetails createKeyDetails = new CreateKeyDetails
            {
                KeyShape      = keyShape,
                CompartmentId = compartmentId,
                DisplayName   = "DotNet-SDK-Key-1",
                FreeformTags  = GetSampleFreeformTagData()
            };
            CreateKeyRequest createKeyRequest = new CreateKeyRequest
            {
                CreateKeyDetails = createKeyDetails
            };
            CreateKeyResponse createKeyResponse = await kmsManagementClient.CreateKey(createKeyRequest);

            logger.Info($"Created new key: {createKeyResponse.Key.DisplayName}");
            return(createKeyResponse.Key.Id);
        }
예제 #2
0
        private static async Task GenerateDataEncryptionKey(KmsCryptoClient kmsCryptoClient, string keyId)
        {
            logger.Info("Generate Data Encryption Key");
            KeyShape keyShape = new KeyShape
            {
                Algorithm = KeyShape.AlgorithmEnum.Aes,
                Length    = DefaultKeyLength
            };
            GenerateKeyDetails generateKeyDetails = new GenerateKeyDetails
            {
                KeyId               = keyId,
                KeyShape            = keyShape,
                IncludePlaintextKey = true,
                LoggingContext      = GetSampleLoggingContext()
            };
            GenerateDataEncryptionKeyRequest generateDataEncryptionKeyRequest = new GenerateDataEncryptionKeyRequest
            {
                GenerateKeyDetails = generateKeyDetails
            };
            GenerateDataEncryptionKeyResponse generateDataEncryptionKeyResponse =
                await kmsCryptoClient.GenerateDataEncryptionKey(generateDataEncryptionKeyRequest);

            logger.Info($"Generated Data Encyption key: {generateDataEncryptionKeyResponse.GeneratedKey.Plaintext}");
        }