/// <summary>
        /// Encrypts and encodes the private key.
        /// </summary>
        /// <param name="key">The private key.</param>
        /// <param name="passPhrase">The pass phrase to encrypt the private key.</param>
        /// <returns>The encrypted private key.</returns>
        public static string ToEncryptedPrivateKeyString(AsymmetricKeyParameter key, string passPhrase)
        {
            var salt         = new byte[16];
            var secureRandom = SecureRandom.GetInstance("SHA256PRNG");

            secureRandom.SetSeed(SecureRandom.GetSeed(16));               //See Bug #135
            secureRandom.NextBytes(salt);

            return(Convert.ToBase64String(PrivateKeyFactory.EncryptKey(keyEncryptionAlgorithm, passPhrase.ToCharArray(), salt, 10, key)));
        }
        public virtual byte[] Encrypt(string password, byte[] salt, int iterationCount, byte[] content)
        {
            AsymmetricKeyParameter asymmetricKey = PrivateKeyFactory.CreateKey(content);

            byte[] encryptedContent = PrivateKeyFactory.EncryptKey(BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc, password.ToCharArray(), salt, iterationCount, asymmetricKey);

            var encryptedKeyPrimitives = (DerSequence)Asn1Object.FromByteArray(encryptedContent);
            var derPrimitives          = new[]
            {
                new DerSequence(new DerObjectIdentifier(BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc.Id),
                                ((DerSequence)encryptedKeyPrimitives[0])[1]),
                encryptedKeyPrimitives[1]
            };

            var keySequence = new DerSequence(derPrimitives);

            return(keySequence.GetDerEncoded());
        }
        public virtual byte[] Encrypt(string password, byte[] salt, int iterationCount, byte[] content)
        {
            AsymmetricKeyParameter asymmetricKey = PrivateKeyFactory.CreateKey(content);

            return(PrivateKeyFactory.EncryptKey(PkcsObjectIdentifiers.PbeWithShaAnd3KeyTripleDesCbc, password.ToCharArray(), salt, iterationCount, asymmetricKey));
        }