Example #1
0
        public ConfigHandler()
        {
            FPCommon oGspCommon = new FPCommon();

            oGspCommon = (FPCommon)System.Configuration.ConfigurationManager.GetSection("GSPCommon");
            //string sEncryptionDecryptionAlgorithm = oGspCommon.CommonSettings.EncryptionDecryptionAlgorithm.ToString().ToUpper();
            CryptographyAlgorithm algorithm = new CryptographyAlgorithm();

            /*  switch (sEncryptionDecryptionAlgorithm)
             *                                {
             *                                        case "DES":
             *                                                algorithm = CryptographyAlgorithm.Des;
             *                                                break;
             *                                        case "MACHINEDPAPI":
             *                                                algorithm = CryptographyAlgorithm.MachineDpApi;
             *                                                break;
             *                                        case "RC2":
             *                                                algorithm = CryptographyAlgorithm.Rc2;
             *                                                break;
             *                                        case "RIJNDAEL":
             *                                                algorithm = CryptographyAlgorithm.Rijndael;
             *                                                break;
             *                                        case "TRIPLEDES":
             *                                                algorithm = CryptographyAlgorithm.TripleDes;
             *                                                break;
             *                                        case "USERDPAPI":
             *                                                algorithm = CryptographyAlgorithm.UserDpApi;
             *                                                break;
             *                                }*/
            CreateHelper(algorithm);
        }
Example #2
0
 private void CreateHelper(CryptographyAlgorithm algorithm, string key)
 {
     if (key.Trim().Length == 0)
     {
         helper = CryptoFactory.Create(algorithm);
     }
     else
     {
         helper = CryptoFactory.Create(algorithm, key);
     }
 }
Example #3
0
 public static ICryptoHelper Create(CryptographyAlgorithm algorithm, string entropy)
 {
     switch (algorithm)
     {
         case CryptographyAlgorithm.Des:
         case CryptographyAlgorithm.Rc2:
         case CryptographyAlgorithm.Rijndael:
         case CryptographyAlgorithm.TripleDes:
             return new SymmetricCryptographyHelper(algorithm, entropy);
         default:
             throw new CryptographicException("Algorithm '" + algorithm + "' not supported.");
     }
 }
Example #4
0
        /// <summary>
        /// Creates an ICryptoHelper based on the algorithm.
        /// </summary>
        /// <exception cref="CryptographicException" >Thrown if an invalid algorithm is provided.</exception>
        /// <param name="algorithm">The cryptographic algorithm to use.</param>
        /// <returns>The created ICryptoHelper.</returns>
        public static ICryptoHelper Create(CryptographyAlgorithm algorithm)
        {
            switch (algorithm)
            {
            case CryptographyAlgorithm.Des:
            case CryptographyAlgorithm.Rc2:
            case CryptographyAlgorithm.Rijndael:
            case CryptographyAlgorithm.TripleDes:
                return(new SymmetricCryptographyHelper(algorithm));

            default:
            {
                throw new CryptographicException("Algorithm '" +
                                                 algorithm +
                                                 "' not supported.");
            }
            }
        }
Example #5
0
        /// <summary>
        /// Creates an ICryptoHelper based on the algorithm using the supplied entropy.
        /// </summary>
        /// <exception cref="CryptographicException" >Thrown if an invalid algorithm is provided.</exception>
        /// <param name="algorithm">The cryptographic algorithm to use.</param>
        /// <param name="entropy">The entropy to use for the encryption algorithm.</param>
        /// <returns>The created ICryptoHelper.</returns>
        public static ICryptoHelper Create(CryptographyAlgorithm algorithm, string entropy)
        {
            switch (algorithm)
            {
            case CryptographyAlgorithm.Des:
            case CryptographyAlgorithm.Rc2:
            case CryptographyAlgorithm.Rijndael:
            case CryptographyAlgorithm.TripleDes:
                return(new SymmetricCryptographyHelper(algorithm, entropy));

            case CryptographyAlgorithm.MachineDpApi:
            case CryptographyAlgorithm.UserDpApi:
            //	return new DataProtector((Store)algorithm, entropy);
            default:
            {
                throw new CryptographicException("Algorithm '" +
                                                 algorithm +
                                                 "' not supported.");
            }
            }
        }
Example #6
0
        /// <summary>
        /// Creates an ICryptoHelper based on the algorithm name using the supplied entropy.
        /// The algorithm name must match one of the name in the EncryptionAlgorithm enumeration.
        /// </summary>
        /// <param name="algorithmName">The name of the cryptographic algorithm to use.</param>
        /// <param name="entropy">The entropy to use for the encryption algorithm.</param>
        /// <returns>The created ICryptoHelper.</returns>
        public static ICryptoHelper Create(string algorithmName, string entropy)
        {
            CryptographyAlgorithm algorithm = (CryptographyAlgorithm)System.Enum.Parse(typeof(CryptographyAlgorithm), algorithmName, true);

            return(Create(algorithm, entropy));
        }
 /// <summary>
 /// Overloaded Constructor
 /// </summary>
 /// <param name="algId">The type of algorithm to use.</param>
 /// <param name="password">Password to use to create the encryption key</param>
 public SymmetricCryptographyHelper(CryptographyAlgorithm algId, string password)
 {
     algorithmId = algId;
     entropy     = password;
 }
 /// <summary>
 /// Overloaded constructor.
 /// </summary>
 /// <param name="algId">The type of algorithm to use.</param>
 public SymmetricCryptographyHelper(CryptographyAlgorithm algId)
 {
     algorithmId = algId;
 }
 public SymmetricCryptographyHelper(CryptographyAlgorithm algId, string password)
 {
     algorithmId = algId;
     entropy = password;
 }
 public SymmetricCryptographyHelper(CryptographyAlgorithm algId)
 {
     algorithmId = algId;
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="algorithm"></param>
 private void CreateHelper(CryptographyAlgorithm algorithm)
 {
     helper = CryptoFactory.Create(algorithm);
 }