/// <summary> /// This constructor is intended to create a new X509Alias pointing to the specified encryption certificate /// </summary> /// <param name="Name">The desired identifier for the alias</param> /// <param name="Thumbprint">The SHA1 thumbprint of the certificate to be used for cryptographic operations. Must exist in the specified Context</param> /// <param name="Context">The context in which to create the alias</param> /// <param name="complainIfExists">If set to true, an exception is thrown if an existing alias identifier is specified for "Name"</param> public X509Alias(string Name, string Thumbprint, X509Context Context, bool complainIfExists) : this(Context) { this.Name = Name; this.Thumbprint = Thumbprint; LoadIfExists(complainIfExists); if (!X509CryptoAgent.CertificateExists(Thumbprint, Context)) { throw new X509CryptoCertificateNotFoundException(Thumbprint, Context); } }
/// <summary> /// Updates this X509Alias to use a new encryption certificate and key pair. The old certificate and key pair must still be available to perform this operation. /// </summary> /// <param name="newThumbprint">The SHA1 thumbprint of the new encryption certificate. The certificate and associated key pair must exist and be available in the specified X509Context</param> /// <param name="newContext">The X509Context where the new encryption certificate and key pair is located</param> public void ReEncrypt(string newThumbprint, X509Context newContext = null) { if (newContext == null) { newContext = Context; } newThumbprint = newThumbprint.RemoveNonHexChars(); if (!X509CryptoAgent.CertificateExists(newThumbprint, newContext)) { throw new X509CryptoException($"A valid encryption certificate with thumbprint {newThumbprint} was not found in the {Context.Name} context"); } foreach (X509Secret secret in Secrets) { secret.ReEncrypt(this, newThumbprint, newContext); } Thumbprint = newThumbprint; Context = newContext; Commit(); }
internal static Dictionary <string, X509Certificate2> GetAll(X509Context Context) { Dictionary <string, X509Certificate2> Aliases = new Dictionary <string, X509Certificate2>(); X509Certificate2Collection CertStore = GetCertificates(Context); X509Alias CurrentAlias; foreach (string aliasName in Context.GetAliasNames()) { CurrentAlias = new X509Alias(aliasName, Context); if (X509CryptoAgent.CertificateExists(CurrentAlias.Thumbprint, Context)) { foreach (X509Certificate2 Cert in CertStore) { if (Cert.Thumbprint.Matches(CurrentAlias.Thumbprint)) { Aliases.Add(aliasName, Cert); break; } } } } return(Aliases); }