Exemplo n.º 1
0
        private PGPKeyInformation ConvertKeyPairInformation(KeyPairInformation kpi)
        {
            PGPKeyInformation ki = null;

            if (kpi != null)
            {
                ki                = new PGPKeyInformation();
                ki.Algorithm      = kpi.Algorithm;
                ki.CreationTime   = kpi.CreationTime;
                ki.EncryptionKey  = kpi.EncryptionKey;
                ki.Fingerprint    = kpi.Fingerprint;
                ki.HasPrivateKey  = kpi.HasPrivateKey;
                ki.IsExpired      = kpi.IsExpired;
                ki.IsLegacyRSAKey = kpi.IsLegacyRSAKey;
                ki.KeyId          = kpi.KeyId;
                ki.KeyIdHex       = kpi.KeyIdHex;
                ki.KeySize        = kpi.KeySize;
                if (kpi.PreferredCompressions != null)
                {
                    ki.PreferredCompressions = new pfPGPCompressionAlgorithm[kpi.PreferredCompressions.Length];
                    for (int j = 0; j < kpi.PreferredCompressions.Length; j++)
                    {
                        ki.PreferredCompressions[j] = (pfPGPCompressionAlgorithm)kpi.PreferredCompressions[j];
                    }
                }
                if (kpi.PreferredCyphers != null)
                {
                    ki.PreferredCyphers = new pfPGPCypherAlgorithm[kpi.PreferredCyphers.Length];
                    for (int j = 0; j < kpi.PreferredCyphers.Length; j++)
                    {
                        ki.PreferredCyphers[j] = (pfPGPCypherAlgorithm)kpi.PreferredCyphers[j];
                    }
                }
                if (kpi.PreferredHashes != null)
                {
                    ki.PreferredHashes = new pfPGPHashAlgorithm[kpi.PreferredHashes.Length];
                    for (int j = 0; j < kpi.PreferredHashes.Length; j++)
                    {
                        ki.PreferredHashes[j] = (pfPGPHashAlgorithm)kpi.PreferredHashes[j];
                    }
                }
                ki.HasPrivateKeyRing = kpi.PrivateRing != null ? true : false;
                ki.HasPrivateSubKeys = kpi.PrivateSubKeys != null ? true : false;
                ki.HasPublicKeyRing  = kpi.PublicRing != null ? true : false;
                ki.HasPublicSubKeys  = kpi.PublicSubKeys != null ? true : false;
                ki.Revoked           = kpi.Revoked;
                ki.SignedWithKeyIds  = kpi.SignedWithKeyIds;
                ki.SigningKey        = kpi.SigningKey;
                ki.Trust             = (pfPGPTrustLevel)kpi.Trust;
                ki.UserId            = kpi.UserId;
                ki.UserIds           = kpi.UserIds;
                ki.ValidDays         = kpi.ValidDays;
            }
            return(ki);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a key pair in  the key store.
        /// </summary>
        /// <param name="keySize">Size for key. Valid values from 1024 to 4096.</param>
        /// <param name="userId">User id for the key.</param>
        /// <param name="keyAlgorithm">Algorithm used for key storage.</param>
        /// <param name="password">Private key password.</param>
        /// <param name="compressionTypes">Types of compression supported in comma delimited format.</param>
        /// <param name="hashingAlgorithmTypes">Types of hashing supported in comma delimited format.</param>
        /// <param name="cypherTypes">Types of cyphers supported in comma delimited format.</param>
        /// <param name="expirationDate">Date at which the key will no longer be valid.</param>
        /// <returns>Returns object with PGP Key information.</returns>
        public PGPKeyInformation CreateKey(int keySize,
                                           string userId,
                                           string keyAlgorithm,
                                           string password,
                                           string compressionTypes,
                                           string hashingAlgorithmTypes,
                                           string cypherTypes,
                                           DateTime expirationDate)
        {
            KeyPairInformation kpi = null;

            if (IsValidKeySize(keySize) == false)
            {
                _msg.Length = 0;
                _msg.Append("Invalid key size: ");
                _msg.Append(keySize.ToString());
                _msg.Append("  Valid key sizes: Min: ");
                _msg.Append(_minValidKeySize.ToString());
                _msg.Append(", Max: ");
                _msg.Append(_maxValidKeySize.ToString());
                _msg.Append(".");
                throw new System.Exception(_msg.ToString());
            }

            if (expirationDate == DateTime.MinValue || expirationDate == DateTime.MaxValue)
            {
                kpi = _keyStore.GenerateKeyPair(keySize,
                                                userId,
                                                ConvertToKeyAlgorithm(keyAlgorithm),
                                                password,
                                                ConvertToCompressionAlgorithmArray(compressionTypes),
                                                ConvertToHashAlgorithmArray(hashingAlgorithmTypes),
                                                ConvertToCypherAlgorithmArray(cypherTypes));
            }
            else
            {
                kpi = _keyStore.GenerateKeyPair(keySize,
                                                userId,
                                                ConvertToKeyAlgorithm(keyAlgorithm),
                                                password,
                                                ConvertToCompressionAlgorithmArray(compressionTypes),
                                                ConvertToHashAlgorithmArray(hashingAlgorithmTypes),
                                                ConvertToCypherAlgorithmArray(cypherTypes),
                                                expirationDate);
            }

            GetKeyList();

            return(ConvertKeyPairInformation(kpi));
        }
Exemplo n.º 3
0
        //methods

        internal void LoadPropertyValuesFromKeyPairInformation(KeyPairInformation kpi)
        {
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a key pair in  the key store.
        /// </summary>
        /// <param name="keySize">Size for key. Valid values from 1024 to 4096.</param>
        /// <param name="userId">User id for the key.</param>
        /// <param name="keyAlgorithm">Algorithm used for key storage.</param>
        /// <param name="password">Private key password.</param>
        /// <param name="compressionTypes">Array containing types of compression supported.</param>
        /// <param name="hashingAlgorithmTypes">Array containing types of hashing supported.</param>
        /// <param name="cypherTypes">Array containing types of cyphers supported.</param>
        /// <param name="expirationDate">Date at which the key will no longer be valid.</param>
        /// <returns>Returns object with PGP Key information.</returns>
        public PGPKeyInformation CreateKey(int keySize,
                                           string userId,
                                           pfKeyAlgorithm keyAlgorithm,
                                           string password,
                                           pfPGPCompressionAlgorithm[] compressionTypes,
                                           pfPGPHashAlgorithm[] hashingAlgorithmTypes,
                                           pfPGPCypherAlgorithm[] cypherTypes,
                                           DateTime expirationDate)
        {
            KeyPairInformation kpi = null;

            if (IsValidKeySize(keySize) == false)
            {
                _msg.Length = 0;
                _msg.Append("Invalid key size: ");
                _msg.Append(keySize.ToString());
                _msg.Append("  Valid key sizes: Min: ");
                _msg.Append(_minValidKeySize.ToString());
                _msg.Append(", Max: ");
                _msg.Append(_maxValidKeySize.ToString());
                _msg.Append(".");
                throw new System.Exception(_msg.ToString());
            }

            if (_keyStore.ContainsKey(userId))
            {
                _msg.Length = 0;
                _msg.Append("User ID (");
                _msg.Append(userId);
                _msg.Append(") already exists in the Key Store (");
                _msg.Append(this.KeyStorePath);
                _msg.Append(").");
                throw new System.Exception(_msg.ToString());
            }

            if (expirationDate == DateTime.MinValue || expirationDate == DateTime.MaxValue)
            {
                kpi = _keyStore.GenerateKeyPair(keySize,
                                                userId,
                                                (KeyAlgorithm)keyAlgorithm,
                                                password,
                                                ConvertToCompressionAlgorithmArray(compressionTypes),
                                                ConvertToHashAlgorithmArray(hashingAlgorithmTypes),
                                                ConvertToCypherAlgorithmArray(cypherTypes));
            }
            else
            {
                kpi = _keyStore.GenerateKeyPair(keySize,
                                                userId,
                                                (KeyAlgorithm)keyAlgorithm,
                                                password,
                                                ConvertToCompressionAlgorithmArray(compressionTypes),
                                                ConvertToHashAlgorithmArray(hashingAlgorithmTypes),
                                                ConvertToCypherAlgorithmArray(cypherTypes),
                                                expirationDate);
            }

            GetKeyList();

            return(ConvertKeyPairInformation(kpi));
        }