Exemplo n.º 1
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>
 /// <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)
 {
     return(CreateKey(keySize, userId, keyAlgorithm, password, compressionTypes, hashingAlgorithmTypes, cypherTypes, DateTime.MaxValue));
 }
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">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));
        }