PBEParameter.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs
  8. {
  9. public class PbeParameter
  10. : Asn1Encodable
  11. {
  12. private readonly Asn1OctetString salt;
  13. private readonly DerInteger iterationCount;
  14. public static PbeParameter GetInstance(object obj)
  15. {
  16. if (obj is PbeParameter || obj == null)
  17. {
  18. return (PbeParameter) obj;
  19. }
  20. if (obj is Asn1Sequence)
  21. {
  22. return new PbeParameter((Asn1Sequence) obj);
  23. }
  24. throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
  25. }
  26. private PbeParameter(Asn1Sequence seq)
  27. {
  28. if (seq.Count != 2)
  29. throw new ArgumentException("Wrong number of elements in sequence", "seq");
  30. salt = Asn1OctetString.GetInstance(seq[0]);
  31. iterationCount = DerInteger.GetInstance(seq[1]);
  32. }
  33. public PbeParameter(byte[] salt, int iterationCount)
  34. {
  35. this.salt = new DerOctetString(salt);
  36. this.iterationCount = new DerInteger(iterationCount);
  37. }
  38. public byte[] GetSalt()
  39. {
  40. return salt.GetOctets();
  41. }
  42. public BigInteger IterationCount
  43. {
  44. get { return iterationCount.Value; }
  45. }
  46. public override Asn1Object ToAsn1Object()
  47. {
  48. return new DerSequence(salt, iterationCount);
  49. }
  50. }
  51. }
  52. #pragma warning restore
  53. #endif