PBES2Parameters.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  5. {
  6. public class PbeS2Parameters
  7. : Asn1Encodable
  8. {
  9. private readonly KeyDerivationFunc func;
  10. private readonly EncryptionScheme scheme;
  11. public static PbeS2Parameters GetInstance(object obj)
  12. {
  13. if (obj == null)
  14. return null;
  15. PbeS2Parameters existing = obj as PbeS2Parameters;
  16. if (existing != null)
  17. return existing;
  18. return new PbeS2Parameters(Asn1Sequence.GetInstance(obj));
  19. }
  20. public PbeS2Parameters(KeyDerivationFunc keyDevFunc, EncryptionScheme encScheme)
  21. {
  22. this.func = keyDevFunc;
  23. this.scheme = encScheme;
  24. }
  25. [Obsolete("Use GetInstance() instead")]
  26. public PbeS2Parameters(
  27. Asn1Sequence seq)
  28. {
  29. if (seq.Count != 2)
  30. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  31. Asn1Sequence funcSeq = (Asn1Sequence)seq[0].ToAsn1Object();
  32. // TODO Not sure if this special case is really necessary/appropriate
  33. if (funcSeq[0].Equals(PkcsObjectIdentifiers.IdPbkdf2))
  34. {
  35. func = new KeyDerivationFunc(PkcsObjectIdentifiers.IdPbkdf2,
  36. Pbkdf2Params.GetInstance(funcSeq[1]));
  37. }
  38. else
  39. {
  40. func = new KeyDerivationFunc(funcSeq);
  41. }
  42. scheme = EncryptionScheme.GetInstance(seq[1].ToAsn1Object());
  43. }
  44. public KeyDerivationFunc KeyDerivationFunc
  45. {
  46. get { return func; }
  47. }
  48. public EncryptionScheme EncryptionScheme
  49. {
  50. get { return scheme; }
  51. }
  52. public override Asn1Object ToAsn1Object()
  53. {
  54. return new DerSequence(func, scheme);
  55. }
  56. }
  57. }
  58. #pragma warning restore
  59. #endif