Example #1
0
        /// <summary>
        /// Exports an OpenPGP public key to a key file.
        /// </summary>
        /// <param name="openPgp">The OpenPGP-compatible system used to manage keys.</param>
        /// <param name="keyID">The key ID to get the public key for.</param>
        /// <param name="path">The directory to write the key file to.</param>
        /// <exception cref="UnauthorizedAccessException">The file could not be read or written.</exception>
        /// <exception cref="UnauthorizedAccessException">Write access to the directory is not permitted.</exception>
        /// <exception cref="IOException">The specified <paramref name="keyID"/> could not be found on the system.</exception>
        public static void DeployPublicKey([NotNull] this IOpenPgp openPgp, [NotNull] IKeyIDContainer keyID, [NotNull] string path)
        {
            #region Sanity checks
            if (openPgp == null)
            {
                throw new ArgumentNullException(nameof(openPgp));
            }
            if (keyID == null)
            {
                throw new ArgumentNullException(nameof(keyID));
            }
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            #endregion

            File.WriteAllText(
                path: Path.Combine(path, keyID.FormatKeyID() + ".gpg"),
                contents: openPgp.ExportKey(keyID),
                encoding: Encoding.ASCII);
        }
Example #2
0
        /// <inheritdoc/>
        public string ExportKey(IKeyIDContainer keyIDContainer)
        {
            #region Sanity checks
            if (keyIDContainer == null) throw new ArgumentNullException(nameof(keyIDContainer));
            #endregion

            return new CliControl(HomeDir).Execute("--batch", "--no-secmem-warning", "--armor", "--export", keyIDContainer.FormatKeyID())
                .Replace(Environment.NewLine, "\n") + "\n";
        }
Example #3
0
        /// <inheritdoc/>
        public string ExportKey(IKeyIDContainer keyIDContainer)
        {
            #region Sanity checks
            if (keyIDContainer == null)
            {
                throw new ArgumentNullException(nameof(keyIDContainer));
            }
            #endregion

            return(new CliControl(HomeDir).Execute("--batch", "--no-secmem-warning", "--armor", "--export", keyIDContainer.FormatKeyID())
                   .Replace(Environment.NewLine, "\n") + "\n");
        }