Example #1
0
        private void ExtendSecrets(X509Secret SecretToAdd, bool overwriteExisting = false)
        {
            if (Secrets == null)
            {
                Secrets    = new X509Secret[1];
                Secrets[0] = SecretToAdd;
            }
            else
            {
                for (int x = 0; x < Secrets.Length; x++)
                {
                    if (Secrets[x].Key.Matches(SecretToAdd.Key))
                    {
                        if (overwriteExisting)
                        {
                            Secrets[x] = SecretToAdd;
                            return;
                        }
                        else
                        {
                            throw new X509SecretAlreadyExistsException(this, SecretToAdd);
                        }
                    }
                }

                X509Secret[] Expanded = new X509Secret[Secrets.Length + 1];
                for (int x = 0; x < Secrets.Length; x++)
                {
                    Expanded[x] = Secrets[x];
                }
                Expanded[Secrets.Length] = SecretToAdd;
                Secrets = Expanded;
            }
        }
Example #2
0
        /// <summary>
        /// Encrypts the specified plaintext expression and stores it in this X509Alias
        /// </summary>
        /// <param name="key">The desired identifier for the secret (must be unique within the alias)</param>
        /// <param name="plaintext">The plaintext expression to be encrypted</param>
        /// <param name="overwriteExisting">Indicates whether an existing secret in the alias with the same value for "Name" as specified may be overwritten</param>
        /// <returns>A Base64-encoded ciphertext string</returns>
        public string AddSecret(string key, string plaintext, bool overwriteExisting)
        {
            X509Secret Secret = new X509Secret(this, key, plaintext);

            ExtendSecrets(Secret, overwriteExisting);
            return(Secret.Value);
        }
Example #3
0
        private void LoadSecret(string key, string ciphertext)
        {
            X509Secret Secret = new X509Secret(key, ciphertext);

            ExtendSecrets(Secret);
        }
Example #4
0
        /// <summary>
        /// Adds a secret (which has already been encrypted using the certificate associated with this X509Alias) and its identifier to this X509Alias
        /// </summary>
        /// <param name="tuple">Key should be the secret identifier, Value should be the encrypted secret</param>
        /// <param name="overwriteExisting">Indicates whether an existing secret in the alias with the same value for "Name" as specified may be overwritten</param>
        public void AddSecret(KeyValuePair <string, string> tuple, bool overwriteExisting)
        {
            X509Secret Secret = new X509Secret(tuple.Key, tuple.Value);

            ExtendSecrets(Secret, overwriteExisting);
        }
Example #5
0
        /// <summary>
        /// Encrypts the specified text expression
        /// </summary>
        /// <param name="plaintext">the text expression to be encrypted</param>
        /// <returns>Base64-encoded ciphertext string</returns>
        public string EncryptText(string plaintext)
        {
            X509Secret Secret = new X509Secret(this, string.Empty, plaintext);

            return(Secret.Value);
        }
Example #6
0
 internal X509SecretAlreadyExistsException(X509Alias Alias, X509Secret Secret)
     : base($"An X509Secret with identifier \"{Secret.Key}\" already exists in the \"{Alias.Name}\" alias.")
 {
 }