public static IMac GetMac(
string algorithm)
{
string upper = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.ToUpperInvariant(algorithm);
string mechanism = (string)algorithms[upper];
if (mechanism == null)
{
mechanism = upper;
}
if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "PBEWITH"))
{
mechanism = mechanism.Substring("PBEWITH".Length);
}
if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "HMAC"))
{
string digestName;
if (BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "HMAC-") || BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.StartsWith(mechanism, "HMAC/"))
{
digestName = mechanism.Substring(5);
}
else
{
digestName = mechanism.Substring(4);
}
return(new HMac(DigestUtilities.GetDigest(digestName)));
}
if (mechanism == "AESCMAC")
{
return(new CMac(new AesEngine()));
}
if (mechanism == "DESMAC")
{
return(new CbcBlockCipherMac(new DesEngine()));
}
if (mechanism == "DESMAC/CFB8")
{
return(new CfbBlockCipherMac(new DesEngine()));
}
if (mechanism == "DESMAC64")
{
return(new CbcBlockCipherMac(new DesEngine(), 64));
}
if (mechanism == "DESEDECMAC")
{
return(new CMac(new DesEdeEngine()));
}
if (mechanism == "DESEDEMAC")
{
return(new CbcBlockCipherMac(new DesEdeEngine()));
}
if (mechanism == "DESEDEMAC/CFB8")
{
return(new CfbBlockCipherMac(new DesEdeEngine()));
}
if (mechanism == "DESEDEMAC64")
{
return(new CbcBlockCipherMac(new DesEdeEngine(), 64));
}
if (mechanism == "DESEDEMAC64WITHISO7816-4PADDING")
{
return(new CbcBlockCipherMac(new DesEdeEngine(), 64, new ISO7816d4Padding()));
}
if (mechanism == "DESWITHISO9797" ||
mechanism == "ISO9797ALG3MAC")
{
return(new ISO9797Alg3Mac(new DesEngine()));
}
if (mechanism == "ISO9797ALG3WITHISO7816-4PADDING")
{
return(new ISO9797Alg3Mac(new DesEngine(), new ISO7816d4Padding()));
}
if (mechanism == "SKIPJACKMAC")
{
return(new CbcBlockCipherMac(new SkipjackEngine()));
}
if (mechanism == "SKIPJACKMAC/CFB8")
{
return(new CfbBlockCipherMac(new SkipjackEngine()));
}
if (mechanism == "IDEAMAC")
{
return(new CbcBlockCipherMac(new IdeaEngine()));
}
if (mechanism == "IDEAMAC/CFB8")
{
return(new CfbBlockCipherMac(new IdeaEngine()));
}
if (mechanism == "RC2MAC")
{
return(new CbcBlockCipherMac(new RC2Engine()));
}
if (mechanism == "RC2MAC/CFB8")
{
return(new CfbBlockCipherMac(new RC2Engine()));
}
if (mechanism == "RC5MAC")
{
return(new CbcBlockCipherMac(new RC532Engine()));
}
if (mechanism == "RC5MAC/CFB8")
{
return(new CfbBlockCipherMac(new RC532Engine()));
}
if (mechanism == "GOST28147MAC")
{
return(new Gost28147Mac());
}
if (mechanism == "VMPCMAC")
{
return(new VmpcMac());
}
if (mechanism == "SIPHASH-2-4")
{
return(new SipHash());
}
throw new SecurityUtilityException("Mac " + mechanism + " not recognised.");
}