Esempio n. 1
0
        private bool IsKeySizeValid(int size, Algorithm algorithm)
        {
            SymmetricAlgorithm alg;

            switch (algorithm)
            {
                case Algorithm.DES:
                    alg = new DESCryptoServiceProvider();
                    break;
                case Algorithm.TripleDES:
                    alg = new TripleDESCryptoServiceProvider();
                    break;
                case Algorithm.RC2:
                    alg = new RC2CryptoServiceProvider();
                    break;
                case Algorithm.Rijndael:
                    alg = Rijndael.Create();
                    break;
                default:
                    return false;
            }

            return alg.ValidKeySize(size);
        }
Esempio n. 2
0
 public static bool ValidateKeySize( EncryptionAlgorithm algID, int Lenght)
 {
     switch (algID)
     {
         case EncryptionAlgorithm.DES:
             DES des = new DESCryptoServiceProvider();
             return des.ValidKeySize(Lenght);
         case EncryptionAlgorithm.Rc2:
             RC2 rc = new RC2CryptoServiceProvider();
             return rc.ValidKeySize(Lenght);
         case EncryptionAlgorithm.Rijndael:
             Rijndael rj = new RijndaelManaged();
             return rj.ValidKeySize(Lenght);
         case EncryptionAlgorithm.TripleDes:
             TripleDES tDes = new TripleDESCryptoServiceProvider();
             return tDes.ValidKeySize(Lenght);
         default:
             throw new CryptographicException("Algorithm " + algID + " Not Supported!");
     }
 }