Utility class for creating HMac object from their names/Oids
Example #1
0
        public static object CreateEngine(
            string algorithm)
        {
            //TODO: SUSTITUIDO
            //string mechanism = (string)algorithms[algorithm.ToUpper(CultureInfo.InvariantCulture)];
            string mechanism = (string)algorithms[algorithm.ToUpper()];

            if (mechanism.StartsWith("PBEwithHmac"))
            {
                string digestName = mechanism.Substring("PBEwithHmac".Length);

                return(MacUtilities.GetMac("HMAC/" + digestName));
            }

            if (mechanism.StartsWith("PBEwithMD2") ||
                mechanism.StartsWith("PBEwithMD5") ||
                mechanism.StartsWith("PBEwithSHA-1"))
            {
                if (mechanism.EndsWith("RC2-CBC"))
                {
                    return(CipherUtilities.GetCipher("RC2/CBC"));
                }

                if (mechanism.EndsWith("RC4"))
                {
                    return(CipherUtilities.GetCipher("RC4"));
                }

                if (mechanism.EndsWith("DES-CBC"))
                {
                    return(CipherUtilities.GetCipher("DES/CBC"));
                }

                if (mechanism.EndsWith("DESEDE-CBC"))
                {
                    return(CipherUtilities.GetCipher("DESEDE/CBC"));
                }
            }

            return(null);
        }
Example #2
0
        public static object CreateEngine(
            string algorithm)
        {
            string mechanism = (string)algorithms[Platform.StringToUpper(algorithm)];

            if (mechanism.StartsWith("PBEwithHmac"))
            {
                string digestName = mechanism.Substring("PBEwithHmac".Length);

                return(MacUtilities.GetMac("HMAC/" + digestName));
            }

            if (mechanism.StartsWith("PBEwithMD2") ||
                mechanism.StartsWith("PBEwithMD5") ||
                mechanism.StartsWith("PBEwithSHA-1"))
            {
                if (mechanism.EndsWith("RC2-CBC"))
                {
                    return(CipherUtilities.GetCipher("RC2/CBC"));
                }

                if (mechanism.EndsWith("RC4"))
                {
                    return(CipherUtilities.GetCipher("RC4"));
                }

                if (mechanism.EndsWith("DES-CBC"))
                {
                    return(CipherUtilities.GetCipher("DES/CBC"));
                }

                if (mechanism.EndsWith("DESEDE-CBC"))
                {
                    return(CipherUtilities.GetCipher("DESEDE/CBC"));
                }
            }

            return(null);
        }
Example #3
0
 public static IMac GetMac(DerObjectIdentifier id)
 {
     return MacUtilities.GetMac(id.Id);
 }
Example #4
0
 public static byte[] DoFinal(IMac mac, byte[] input)
 {
     mac.BlockUpdate(input, 0, input.Length);
     return MacUtilities.DoFinal(mac);
 }