PBEParameter.cs 1.4 KB

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