예제 #1
0
        public static async Task Main()
        {
            // Note that if you need to create a Key in an AWS Region
            // other than the region defined for the default user, you need to
            // pass the region to the client constructor.
            var client = new AmazonKeyManagementServiceClient();

            // The call to CreateKeyAsync will create a symmetrical AWS KMS
            // key. For more information about symmetrical and asymmetrical
            // keys, see:
            //
            // https://docs.aws.amazon.com/kms/latest/developerguide/symm-asymm-choose.html
            var response = await client.CreateKeyAsync(new CreateKeyRequest());

            // The KeyMetadata object contains information about the new AWS KMS key.
            KeyMetadata keyMetadata = response.KeyMetadata;

            if (keyMetadata is not null)
            {
                Console.WriteLine($"KMS Key: {keyMetadata.KeyId} was successfully created.");
            }
            else
            {
                Console.WriteLine("Could not create KMS Key.");
            }
        }
예제 #2
0
        public override int Run(string[] remainingArguments)
        {
            KeyPurpose purpose = _pupose == "sign" ? KeyPurpose.SignAndVerify : KeyPurpose.DecryptAndEncrypt;

            KeyType type = PickKeyType(purpose);


            var meta = new KeyMetadata()
            {
                Name    = _name,
                Purpose = purpose,
                KeyType = type,
            };

            using (var keySet = new MutableKeySet(meta))
            {
                if (keySet.Save(new KeySetWriter(_location)))
                {
                    Console.WriteLine(Localized.MsgCreatedKeySet);
                    return(0);
                }
            }
            Console.WriteLine("{0} {1}.", Localized.MsgExistingKeySet, _location);

            return(-1);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("You must supply a Region, bucket name, and item name:");
                Console.WriteLine("Usage: KmsS3Encryption REGION BUCKET ITEM");
                return;
            }

            string regionName = args[0];
            string bucketName = args[1];
            string itemName   = args[2];

            Task <CreateKeyResponse> response = MyCreateKeyAsync(regionName);

            KeyMetadata keyMetadata = response.Result.KeyMetadata;
            string      kmsKeyId    = keyMetadata.KeyId;

            // An object that contains information about the CMK created by this operation.
            EncryptionMaterials kmsEncryptionMaterials = new EncryptionMaterials(kmsKeyId);

            Task <GetObjectResponse> goResponse = MyPutObjectAsync(kmsEncryptionMaterials, bucketName, itemName);

            Stream       stream = goResponse.Result.ResponseStream;
            StreamReader reader = new StreamReader(stream);

            Console.WriteLine(reader.ReadToEnd());

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
예제 #4
0
        public override int Run(string[] remainingArguments)
        {
            KeyPurpose purpose = _pupose == "sign" ? KeyPurpose.SignAndVerify : KeyPurpose.DecryptAndEncrypt;

            KeyType officalKeyType = null;

            if (!_unofficial)
            {
                officalKeyType = PickKeyTypeOfficialKeyczar(purpose);
            }


            var meta = new KeyMetadata(officialMetaDataKeyType: officalKeyType)
            {
                Name    = _name,
                Purpose = purpose,
                Kind    = _asymm ? KeyKind.Private : KeyKind.Symmetric,
            };

            using (var keySet = new MutableKeySet(meta))
            {
                if (keySet.Save(new FileSystemKeySetWriter(_location)))
                {
                    Console.WriteLine(Localized.MsgCreatedKeySet);
                    return(0);
                }
            }
            Console.WriteLine("{0} {1}.", Localized.MsgExistingKeySet, _location);

            return(-1);
        }
예제 #5
0
        public IQueryable <KeyMetadata> GetKeyMetadata()
        {
            var sqlDefinition = getSQLDefinition(typeof(KeyMetadata).GetCustomAttribute <SQLServerMetadataAttribute>().SQLDefinitionResource);

            return(KeyMetadata
                   .FromSql(sqlDefinition)
                   .AsQueryable());
        }
 public KeyValueConfigurationValidationResult(
     KeyMetadata keyMetadata,
     IEnumerable <string> values,
     IEnumerable <ValidationError>?validationErrors = default)
 {
     KeyMetadata      = keyMetadata;
     Values           = values.SafeToImmutableArray();
     ValidationErrors = validationErrors !.SafeToImmutableArray();
 }
예제 #7
0
        public override int Run(string[] remainingArguments)
        {
            var keyTypeSpecs = KeyType.Specs.Where(it => !it.Public && !it.Temp).ToList();

            void writeTypes(bool symmetric, bool encrypt)
            {
                var dummyMetaData = new KeyMetadata();

                dummyMetaData.OriginallyOfficial = !_unofficial;
                dummyMetaData.Kind    = symmetric ? KeyKind.Symmetric : KeyKind.Private;
                dummyMetaData.Purpose = encrypt ? KeyPurpose.DecryptAndEncrypt : KeyPurpose.SignAndVerify;



                var keyInterface = encrypt ? typeof(IEncrypterKey) : typeof(ISignerKey);

                foreach (var t in  keyTypeSpecs.Where(it => (!it.Unofficial || _unofficial) &&
                                                      (it.Asymmetric ^ symmetric) &&
                                                      keyInterface.IsAssignableFrom(it.RepresentedType)))
                {
                    var isDefault = t.Name == dummyMetaData.DefaultKeyType ? "*" : " ";
                    var sizes     = String.Join(",", t.KeySizes.Select((it, i) => it.ToString() + (i == 0 ? "*" : "")));

                    var map = AddKey.KeyTypeMaps.FirstOrDefault(it => it.Item1 == t.Name);

                    if (map == null)
                    {
                        throw new Exception($"Missing map for {t.Name}");
                    }

                    // ReSharper disable once LocalizableElement
                    Console.WriteLine($"    {(map.Item2 + isDefault).PadRight(14)} ({sizes})");
                }
            }

            Console.WriteLine(Localized.KeyTypes_Run_Encrypt_and_Decrypt_);
            Console.WriteLine(Localized.KeyTypes_Run___Symmetric_);
            writeTypes(symmetric: true, encrypt: true);


            Console.WriteLine(Localized.KeyTypes_Run___Asymmetric_);
            writeTypes(symmetric: false, encrypt: true);

            Console.WriteLine(Localized.KeyTypes_Run_Sign_and_Verify_);
            Console.WriteLine(Localized.KeyTypes_Run___Symmetric_);
            writeTypes(symmetric: true, encrypt: false);

            Console.WriteLine(Localized.KeyTypes_Run___Asymmetric_);
            writeTypes(symmetric: false, encrypt: false);

            Console.WriteLine();
            Console.WriteLine(Localized.KeyTypes_Run____denotes_default_);
            return(0);
        }
예제 #8
0
        public void KeyManagementServiceCreateKey()
        {
            #region to-create-a-cmk-1478028992966

            var client   = new AmazonKeyManagementServiceClient();
            var response = client.CreateKey(new CreateKeyRequest
            {
            });

            KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.

            #endregion
        }
예제 #9
0
        public void KeyManagementServiceCreateKey()
        {
            #region to-create-a-multi-region-primary-kms-key-1630599158567

            var client   = new AmazonKeyManagementServiceClient();
            var response = client.CreateKey(new CreateKeyRequest
            {
                MultiRegion = true // Indicates whether the KMS key is a multi-Region (True) or regional (False) key.
            });

            KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.

            #endregion
        }
예제 #10
0
        public void KeyManagementServiceCreateKey()
        {
            #region to-create-a-kms-key-for-imported-key-material-1630603607560

            var client   = new AmazonKeyManagementServiceClient();
            var response = client.CreateKey(new CreateKeyRequest
            {
                Origin = "EXTERNAL" // The source of the key material for the KMS key.
            });

            KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.

            #endregion
        }
예제 #11
0
        public void TestCreateBlob()
        {
            Directory.CreateDirectory(Util.TestDataPath(WRITE_DATA, ""));

            var keyMetaData = new KeyMetadata
            {
                Name    = "Blob",
                Purpose = KeyPurpose.DecryptAndEncrypt,
                Kind    = KeyKind.Symmetric
            };

            using (var keySet = new MutableKeySet(keyMetaData))
            {
                keySet.AddKey(KeyStatus.Primary, 256);

                using (var stream = File.OpenWrite(Util.TestDataPath(WRITE_DATA, "cryptkey.zip", "unofficial")))
                    using (var writer = new BlobKeySetWriter(stream))
                    {
                        keySet.Save(writer);
                    }

                using (var crypt = new Crypter(keySet))
                {
                    File.WriteAllText(Util.TestDataPath(WRITE_DATA, "crypt.out", "unofficial"), crypt.Encrypt(input));
                    var keyMetaData2 = new KeyMetadata
                    {
                        Name    = "Blob",
                        Purpose = KeyPurpose.SignAndVerify,
                        Kind    = KeyKind.Private
                    };

                    using (var keySet2 = new MutableKeySet(keyMetaData2))
                    {
                        keySet2.AddKey(KeyStatus.Primary);
                        using (var stream2 = File.OpenWrite(Util.TestDataPath(WRITE_DATA, "signkey.zip", "unofficial")))
                            using (var writer2 = new BlobKeySetWriter(stream2))
                            {
                                keySet2.Save(new EncryptedKeySetWriter(writer2, crypt));
                            }

                        using (var signer = new Signer(keySet2))
                        {
                            File.WriteAllText(Util.TestDataPath(WRITE_DATA, "sign.out", "unofficial"),
                                              signer.Sign(input));
                        }
                    }
                }
            }
        }
예제 #12
0
        public void KeyManagementServiceCreateKey()
        {
            #region to-create-an-asymmetric-rsa-kms-key-for-encryption-and-decryption-1630533897833

            var client   = new AmazonKeyManagementServiceClient();
            var response = client.CreateKey(new CreateKeyRequest
            {
                KeySpec  = "RSA_4096",       // Describes the type of key material in the KMS key.
                KeyUsage = "ENCRYPT_DECRYPT" // The cryptographic operations for which you can use the KMS key.
            });

            KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.

            #endregion
        }
예제 #13
0
        public void KeyManagementServiceCreateKey()
        {
            #region to-create-an-asymmetric-elliptic-curve-kms-key-for-signing-and-verification-1630541089401

            var client   = new AmazonKeyManagementServiceClient();
            var response = client.CreateKey(new CreateKeyRequest
            {
                KeySpec  = "ECC_NIST_P521", // Describes the type of key material in the KMS key.
                KeyUsage = "SIGN_VERIFY"    // The cryptographic operations for which you can use the KMS key.
            });

            KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.

            #endregion
        }
예제 #14
0
        public void KeyManagementServiceCreateKey()
        {
            #region to-create-a-kms-key-in-a-custom-key-store-1630604382908

            var client   = new AmazonKeyManagementServiceClient();
            var response = client.CreateKey(new CreateKeyRequest
            {
                CustomKeyStoreId = "cks-1234567890abcdef0", // Identifies the custom key store that hosts the KMS key.
                Origin           = "AWS_CLOUDHSM"           // Indicates the source of the key material for the KMS key.
            });

            KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.

            #endregion
        }
예제 #15
0
 private static void ValidateKeyMetadata(KeyMetadata keyMetadata, bool keyEnabled, bool isCopy = false)
 {
     Assert.IsNotNull(keyMetadata);
     Assert.IsNotNull(keyMetadata.Arn);
     Assert.IsNotNull(keyMetadata.AWSAccountId);
     Assert.IsNotNull(keyMetadata.Description);
     Assert.IsTrue(keyMetadata.Description.IndexOf(keyDescription, StringComparison.Ordinal) >= 0);
     if (isCopy)
     {
         Assert.IsTrue(keyMetadata.Description.IndexOf(copyText, StringComparison.Ordinal) >= 0);
     }
     Assert.IsNotNull(keyMetadata.KeyId);
     Assert.AreEqual(keyMetadata.KeyUsage, KeyUsageType.ENCRYPT_DECRYPT);
     Assert.AreEqual(keyEnabled, keyMetadata.Enabled);
     Assert.AreNotEqual(DateTime.MinValue, keyMetadata.CreationDate);
 }
예제 #16
0
 public ImportedKeySet(IEnumerable <Key> keys, KeyPurpose purpose, string description = null)
 {
     _key      = keys.ToList();
     _metadata = new KeyMetadata()
     {
         Name     = description,
         Purpose  = purpose,
         Kind     = keys.First().KeyType.Kind,
         Versions = keys.Select((it, i) =>
                                new KeyVersion(
                                    i == 0 ? KeyStatus.Primary : KeyStatus.Active,
                                    i + 1,
                                    it
                                    )).ToList()
     };
 }
예제 #17
0
파일: RoomKey.cs 프로젝트: Jaxwood/aoc2020
        public KeyMetadata Handshake(long subjectNumber, Predicate <KeyMetadata> condition)
        {
            var loopSize = 1L;
            var value    = 1L;

            while (true)
            {
                value *= subjectNumber;
                value %= 20201227;
                var key = new KeyMetadata(value, loopSize);
                if (condition(key))
                {
                    return(key);
                }
                loopSize++;
            }
        }
        public void KeyManagementServiceCreateKey()
        {
            #region to-create-a-cmk-1478028992966

            var response = client.CreateKey(new CreateKeyRequest
            {
                Tags = new List <Tag> {
                    new Tag {
                        TagKey   = "CreatedBy",
                        TagValue = "ExampleUser"
                    }
                } // One or more tags. Each tag consists of a tag key and a tag value.
            });

            KeyMetadata keyMetadata = response.KeyMetadata; // An object that contains information about the CMK created by this operation.

            #endregion
        }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImportedKeySet"/> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="purpose">The purpose.</param>
 /// <param name="description">The description.</param>
 public ImportedKeySet(Key key, KeyPurpose purpose, string description = null)
 {
     _key.Add(key);
     _metadata = new KeyMetadata()
     {
         Name     = description ?? "Imported " + key.KeyType.Identifier,
         Purpose  = purpose,
         Kind     = key.KeyType.Kind,
         Versions = new List <KeyVersion>
         {
             new KeyVersion(
                 KeyStatus.Primary,
                 1,
                 key
                 )
         }
     };
 }
예제 #20
0
        protected override List <AnimationMetadata> Parse()
        {
            List <AnimationMetadata> animations = new List <AnimationMetadata>();

            foreach (PackFileEntry entry in Resources.XmlFiles)
            {
                if (!entry.Name.StartsWith("anikeytext"))
                {
                    continue;
                }

                XmlDocument document = Resources.XmlMemFile.GetDocument(entry.FileHeader);
                foreach (XmlNode animationNode in document.DocumentElement.ChildNodes)
                {
                    AnimationMetadata metadata = new AnimationMetadata();

                    if (animationNode.Name == "kfm")
                    {
                        metadata.ActorId = animationNode.Attributes["name"].Value;
                    }
                    foreach (XmlNode sequenceNode in animationNode)
                    {
                        if (sequenceNode.Name != "seq")
                        {
                            continue;
                        }

                        SequenceMetadata sequence = new SequenceMetadata();
                        sequence.SequenceId   = short.Parse(sequenceNode.Attributes["id"].Value);
                        sequence.SequenceName = sequenceNode.Attributes["name"].Value;
                        foreach (XmlNode keyNode in sequenceNode)
                        {
                            KeyMetadata key = new KeyMetadata();
                            key.KeyName = keyNode.Attributes["name"].Value;
                            key.KeyTime = float.Parse(keyNode.Attributes["time"].Value);
                            sequence.Keys.Add(key);
                        }
                        metadata.Sequence.Add(sequence);
                    }
                    animations.Add(metadata);
                }
            }
            return(animations);
        }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImportedKeySet"/> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="purpose">The purpose.</param>
 /// <param name="description">The description.</param>
 public ImportedKeySet(Key key, KeyPurpose purpose, string description = null)
 {
     _key = key;
     var keyType = key.KeyType;
     _metadata = new KeyMetadata()
                     {
                         Name = description ?? "Imported" + key.KeyType.Identifier,
                         Purpose = purpose,
                         KeyType = keyType,
                         Versions = new List<KeyVersion>
                                        {
                                            new KeyVersion
                                                {
                                                    VersionNumber = 0,
                                                    Status = KeyStatus.Primary,
                                                    Exportable = false
                                                }
                                        }
                     };
 }
예제 #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImportedKeySet"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="purpose">The purpose.</param>
        /// <param name="description">The description.</param>
        public ImportedKeySet(Key key, KeyPurpose purpose, string description = null)
        {
            _key = key;
            var keyType = key.KeyType;

            _metadata = new KeyMetadata()
            {
                Name     = description ?? "Imported" + key.KeyType.Identifier,
                Purpose  = purpose,
                KeyType  = keyType,
                Versions = new List <KeyVersion>
                {
                    new KeyVersion
                    {
                        VersionNumber = 0,
                        Status        = KeyStatus.Primary,
                        Exportable    = false
                    }
                }
            };
        }
예제 #23
0
        private void ValidateKey(string keyId, bool keyEnabled, bool isCopy = false)
        {
            var stopTime = DateTime.Now + keyMaxWait;

            KeyMetadata keyMetadata = null;

            while (DateTime.Now < stopTime)
            {
                try
                {
                    keyMetadata = Client.DescribeKey(keyId).KeyMetadata;
                    ValidateKeyMetadata(keyMetadata, keyEnabled);
                    break;
                }
                catch (AssertFailedException)
                {
                    Thread.Sleep(keyDescribeWait);
                }
            }

            ValidateKeyMetadata(keyMetadata, keyEnabled);
        }
예제 #24
0
        public Channel(string id, List <User> members, KeyMetadata keyMetadata, string name = null)
        {
            Id             = id;
            Members        = members;
            KeyInformation = keyMetadata;

            if (keyMetadata == KeyMetadata.InitiatorKeyNotDisplayed)
            {
                var key  = _keyHandler.ProduceKeys(8100);
                var _key = "";
                foreach (var number in key)
                {
                    var keyA = number / 90 + 1;
                    var keyB = number % 90 + 1;
                    _key = _key + MathematicalMappingLogic.TransformationTable[keyA] + MathematicalMappingLogic.TransformationTable[keyB];
                }

                DependencyService.Get <IStorage>().SetValueWithKey(Id, _key);
            }

            if (name == null)
            {
                if (members.Count > 1)
                {
                    Name = members[0].Username + " " + AppResources.And + " " + (members.Count - 1) + " " + AppResources.MoreMembers;
                }
                else
                {
                    Name = members[0].Username;
                }
            }
            else
            {
                Name = name;
            }
        }
예제 #25
0
 public void Write(KeyMetadata metadata)
 => WriteFile("meta", this.GetConfig().RawStringEncoding.GetBytes(metadata.ToJson()));
예제 #26
0
 /// <summary>
 /// Writes the specified metadata.
 /// </summary>
 /// <param name="metadata">The metadata.</param>
 public void Write(KeyMetadata metadata)
 {
     _zipFile.AddEntry("meta", metadata.ToJson());
 }
예제 #27
0
 public void Write(KeyMetadata metadata)
 {
     metadata.Encrypted = true;
     _writer.Write(metadata);
 }