GetCanonicalAlgorithmName() публичный статический Метод

public static GetCanonicalAlgorithmName ( string algorithm ) : string
algorithm string
Результат string
Пример #1
0
        public static Asn1Encodable GenerateParameters(string algorithm, SecureRandom random)
        {
            if (algorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }
            string canonicalAlgorithmName = ParameterUtilities.GetCanonicalAlgorithmName(algorithm);

            if (canonicalAlgorithmName == null)
            {
                throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
            }
            int num = ParameterUtilities.FindBasicIVSize(canonicalAlgorithmName);

            if (num != -1)
            {
                return(ParameterUtilities.CreateIVOctetString(random, num));
            }
            if (canonicalAlgorithmName == "CAST5")
            {
                return(new Cast5CbcParameters(ParameterUtilities.CreateIV(random, 8), 128));
            }
            if (canonicalAlgorithmName == "IDEA")
            {
                return(new IdeaCbcPar(ParameterUtilities.CreateIV(random, 8)));
            }
            if (canonicalAlgorithmName == "RC2")
            {
                return(new RC2CbcParameter(ParameterUtilities.CreateIV(random, 8)));
            }
            throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
        }
Пример #2
0
        public static KeyParameter CreateKeyParameter(string algorithm, byte[] keyBytes, int offset, int length)
        {
            if (algorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }
            string canonicalAlgorithmName = ParameterUtilities.GetCanonicalAlgorithmName(algorithm);

            if (canonicalAlgorithmName == null)
            {
                throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
            }
            if (canonicalAlgorithmName == "DES")
            {
                return(new DesParameters(keyBytes, offset, length));
            }
            if (canonicalAlgorithmName == "DESEDE" || canonicalAlgorithmName == "DESEDE3")
            {
                return(new DesEdeParameters(keyBytes, offset, length));
            }
            if (canonicalAlgorithmName == "RC2")
            {
                return(new RC2Parameters(keyBytes, offset, length));
            }
            return(new KeyParameter(keyBytes, offset, length));
        }
Пример #3
0
        public static ICipherParameters GetCipherParameters(string algorithm, ICipherParameters key, Asn1Object asn1Params)
        {
            if (algorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }
            string canonicalAlgorithmName = ParameterUtilities.GetCanonicalAlgorithmName(algorithm);

            if (canonicalAlgorithmName == null)
            {
                throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
            }
            byte[] array = null;
            try
            {
                int num = ParameterUtilities.FindBasicIVSize(canonicalAlgorithmName);
                if (num != -1 || canonicalAlgorithmName == "RIJNDAEL" || canonicalAlgorithmName == "SKIPJACK" || canonicalAlgorithmName == "TWOFISH")
                {
                    array = ((Asn1OctetString)asn1Params).GetOctets();
                }
                else if (canonicalAlgorithmName == "CAST5")
                {
                    array = Cast5CbcParameters.GetInstance(asn1Params).GetIV();
                }
                else if (canonicalAlgorithmName == "IDEA")
                {
                    array = IdeaCbcPar.GetInstance(asn1Params).GetIV();
                }
                else if (canonicalAlgorithmName == "RC2")
                {
                    array = RC2CbcParameter.GetInstance(asn1Params).GetIV();
                }
            }
            catch (Exception innerException)
            {
                throw new ArgumentException("Could not process ASN.1 parameters", innerException);
            }
            if (array != null)
            {
                return(new ParametersWithIV(key, array));
            }
            throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised.");
        }