public static ICipherParameters GetCipherParameters( string algorithm, ICipherParameters key, Asn1Object asn1Params) { if (algorithm == null) { throw new ArgumentNullException("algorithm"); } string upper = algorithm.ToUpper(CultureInfo.InvariantCulture); string mechanism = (string)algorithms[upper]; if (mechanism == null) { mechanism = upper; } byte[] iv = null; try { switch (mechanism) { case "AES": case "BLOWFISH": case "DES": case "DESEDE": case "RIJNDAEL": case "SKIPJACK": case "TWOFISH": iv = ((Asn1OctetString)asn1Params).GetOctets(); break; case "RC2": iv = RC2CbcParameter.GetInstance(asn1Params).GetIV(); break; case "IDEA": iv = IdeaCbcPar.GetInstance(asn1Params).GetIV(); break; case "CAST5": iv = Cast5CbcParameters.GetInstance(asn1Params).GetIV(); break; } } catch (Exception e) { throw new ArgumentException("Could not process ASN.1 parameters", "asn1Params", e); } if (iv != null) { return(new ParametersWithIV(key, iv)); } throw new SecurityUtilityException("Algorithm " + mechanism + " not recognised."); }
public static ICipherParameters GetCipherParameters( string algorithm, ICipherParameters key, Asn1Object asn1Params) { if (algorithm == null) { throw new ArgumentNullException("algorithm"); } string canonical = GetCanonicalAlgorithmName(algorithm); if (canonical == null) { throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised."); } byte[] iv = null; try { // TODO These algorithms support an IV // but JCE doesn't seem to provide an AlgorithmParametersGenerator for them // "RIJNDAEL", "SKIPJACK", "TWOFISH" int basicIVKeySize = FindBasicIVSize(canonical); if (basicIVKeySize != -1 || canonical == "RIJNDAEL" || canonical == "SKIPJACK" || canonical == "TWOFISH") { iv = ((Asn1OctetString)asn1Params).GetOctets(); } else if (canonical == "CAST5") { iv = Cast5CbcParameters.GetInstance(asn1Params).GetIV(); } #if INCLUDE_IDEA else if (canonical == "IDEA") { iv = IdeaCbcPar.GetInstance(asn1Params).GetIV(); } #endif else if (canonical == "RC2") { iv = RC2CbcParameter.GetInstance(asn1Params).GetIV(); } } catch (Exception e) { throw new ArgumentException("Could not process ASN.1 parameters", e); } if (iv != null) { return(new ParametersWithIV(key, iv)); } throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised."); }
public static ICipherParameters GetCipherParameters(string algorithm, ICipherParameters key, Asn1Object asn1Params) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) if (algorithm == null) { throw new ArgumentNullException("algorithm"); } string canonicalAlgorithmName = GetCanonicalAlgorithmName(algorithm); if (canonicalAlgorithmName == null) { throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised."); } byte[] array = null; try { int num = 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 (global::System.Exception ex) { throw new ArgumentException("Could not process ASN.1 parameters", ex); } if (array != null) { return(new ParametersWithIV(key, array)); } throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised."); }
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."); }
public static ICipherParameters GetCipherParameters( string algorithm, ICipherParameters key, Asn1Object asn1Params) { if (algorithm == null) { throw new ArgumentNullException("algorithm"); } string canonical = GetCanonicalAlgorithmName(algorithm); if (canonical == null) { throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised."); } byte[] iv = null; try { switch (canonical) { case "AES": case "AES128": case "AES192": case "AES256": case "BLOWFISH": case "CAMELLIA": case "CAMELLIA128": case "CAMELLIA192": case "CAMELLIA256": case "DES": case "DESEDE": case "DESEDE3": case "NOEKEON": case "RIJNDAEL": case "SEED": case "SKIPJACK": case "TWOFISH": iv = ((Asn1OctetString)asn1Params).GetOctets(); break; case "RC2": iv = RC2CbcParameter.GetInstance(asn1Params).GetIV(); break; case "IDEA": iv = IdeaCbcPar.GetInstance(asn1Params).GetIV(); break; case "CAST5": iv = Cast5CbcParameters.GetInstance(asn1Params).GetIV(); break; } } catch (Exception e) { throw new ArgumentException("Could not process ASN.1 parameters", e); } if (iv != null) { return(new ParametersWithIV(key, iv)); } throw new SecurityUtilityException("Algorithm " + algorithm + " not recognised."); }